【发布时间】:2023-03-11 08:06:01
【问题描述】:
好的,假设我有一个如下所示的表格:
<table class="first-table" border="1" width="400px">
<tr>
<td><?php echo $row_cond['title']; ?></td>
<td><a class="more" href="#" onClick="slideup()">Display More</a></td>
</tr>
<tr class="full_result">
<td colspan="2"><?php echo $row_cond['description']; ?></td>
</tr>
</table>
您可以看到我有一个链接,单击该链接将调用slideUp() 函数来显示或隐藏带有“full_result”类的tr:
var command = false;
function slideup() { //New function SlidUp
if (command == false){
$('.full_result').fadeIn();
$('.more').text('Display More');
command = true;
}else{
$('.full_result').hide();
$('.more').text('Display Less');
command = false;
}
}
所以诀窍是,这是在一个 while 循环中并重复多次。那么我该如何做到这一点,以便当我点击链接时,我点击链接的表格中只显示类“full_result”。
当我点击任意表格中的按钮时,所有类同时显示和隐藏。
我的解决方案
$('.full_result').hide();
$(".more").on("click",function(){
$('.more').html('Display More');
$('.full_result').hide();
$(this).parents("tr").next().next().fadeIn();
$(this).html('');
return false; //This stops the page jumping to the top of the page when I click the link
});
【问题讨论】:
-
可能您可以考虑使用
ID而不是class来满足您的要求。
标签: php javascript jquery while-loop show-hide