[英]how to hide data table show entries in javascript and jquery?
[英]Show/Hide a portion of table entries
我有一個10行的html表。 我想在5秒鍾內顯示表格的前5行,在另外5秒鍾內顯示接下來的5行。 當顯示一組行時,另一組行應隱藏。
請幫助
感謝和問候,
阿布
這是在前五行和后五行之間連續循環的一種粗略而有效的方法:
$(document).ready(function() {
var $rows = $("table tr"),
i = 0;
function cycle() {
$rows.hide();
$rows.slice(i, i + 5).show();
i = (i + 5) % $rows.length;
setTimeout(cycle, 5000);
}
cycle();
});
您需要將表分為兩個部分(div),然后使用setTimeout()和JQuery的toggle()來切換這些部分。 試一試!
好的,據我對您的要求的理解,我已對此進行了編碼。 請檢查這是您想要的。
<table width="100">
<tr class="first-five-tr">
<td>first</td>
</tr>
<tr class="first-five-tr">
<td>first</td>
</tr>
<tr class="first-five-tr">
<td>first</td>
</tr>
<tr class="first-five-tr">
<td>first</td>
</tr>
<tr class="first-five-tr">
<td>first</td>
</tr>
<tr class="second-five-tr">
<td>second</td>
</tr>
<tr class="second-five-tr">
<td>second</td>
</tr>
<tr class="second-five-tr">
<td>second</td>
</tr>
<tr class="second-five-tr">
<td>second</td>
</tr>
<tr class="second-five-tr">
<td>second</td>
</tr>
</table>
<script>
var hideFirstfive = null;
function hideSecondFive() {
$('.second-five-tr').hide();
$('.first-five-tr').show();
clearInterval(hideSecondfive);
hideFirstfive = setInterval(hideFirstFive, 5000);
}
function hideFirstFive() {
$('.first-five-tr').hide();
$('.second-five-tr').show();
clearInterval(hideFirstfive);
hideSecondfive = setInterval(hideSecondFive, 5000);
}
var hideSecondfive = setInterval(hideSecondFive, 5000);
</script>
這是工作的小提琴:) http://jsfiddle.net/Dilip_naga_kumar/HVWDD/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.