Ich habe eine dynamische Tabelle, in der Zeilen und Tabellen dynamisch erstellt werden. Ich habe eine Bildlaufleiste, die mit CSS eingestellt ist. Ich habe versucht, Bildlaufleiste anzuzeigen, wenn Zeile> 2 mit js, aber es hat nicht funktioniert. Ich möchte die Bildlaufleiste anzeigen, wenn die Zeile größer als 2 ist. Bitte leiten Sie mich dazu, dies zu erreichen. Für weitere Informationen schauen Sie sich den folgenden Code an (der Code hat 2 Tabellen nur für Test). Jede Hilfe wird sehr geschätztvertikale Bildlaufleiste basierend auf der Anzahl der Zeilen.js jquery
werden//i want to display scroll bar based on number of rows if row >2 then display the scroll bar
//this is how i am adding row in my table
if ($('#testbody2 >tr').length > 2){
\t \t $('#testbody2').css('overflow-y', 'visible');}
.table1 th{
\t border:2px solid black;
}
.table1 tbody{
\t display:inline-block;
\t
\t max-height: 80px;
overflow-y: auto;
}
.table2 tbody{
\t display:block;
\t
\t height: 25px;
overflow-y: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h3>my first table</h3>
<div>
<table class="table1">
<thead>
<tr>test1</tr>
</thead>
<tbody id="testbody">
<tr><td>test</td></tr>
<tr><td>test</td>
</tr><tr>
<td>test</td></tr>
</tbody>
</table>
</div>
<h3>my second table</h3>
<div>
<table class="table2">
<thead>
<tr>test3</tr>
</thead>
<tbody id="testbody2">
<tr><td>test</td></tr>
<tr><td>test</td></tr>
</tr><td>testing</td></tr>
<tr><td>testing</td><tr>
<td>test</td></tr>
</tbody>
</table>
</div>
Luke es nicht funktioniert hat. – david
Sie müssen overflow-y: hidden; In Ihrem CSS müssen Sie auch eine Höhe für das Element festlegen. –
Ich möchte die Höhe nicht einstellen, kann ich es trotzdem tun, ohne Höhe zu setzen, nur nach Anzahl der Zeilen? – david