[英]showing hiding div not working
Hi all I have the following html code 大家好,我有以下html代码
<div id="orderlist">
<div class="panel" id="1">
<div class="p_header">Order No: 1
<input class="ordview" type="button" value="View Details"/>
<input class="select" type="button" value="Add"/>
</div>
<div class="p-content" style="display:none;">
<table>
<tr><td>Contact Person:</td><td></td></tr>
<tr><td>Telephone:</td><td></td></tr>
<tr><td>E-Mail:</td><td></td></tr>
<tr><td>Address:</td><td></td></tr>
<tr><td></td><td></td></tr>
<tr><td>Code</td><td></td></tr>
<tr><td>City</td><td></td></tr>
</table>
</div>
</div>
</div>
with the following jquery to toggle it but it is not working, cannot figure out why though 用下面的jQuery来切换它,但它不起作用,虽然不知道为什么
$("body").on('click',".ordview",function(){
$(this).closest('div.p-content').css('display','block');
alert('view button clicked');
});
.closest()
goes up the DOM and p.content
isn't an ancestor, but div.panel
is. .closest()
进入DOM, p.content
不是祖先,而div.panel
是祖先。 Use: 采用:
$("body").on('click', ".ordview", function () {
$(this).closest('div.panel').find('div.p-content').toggle();
});
Try this code to show/hide details 尝试使用此代码显示/隐藏详细信息
$(".ordview").bind('click', function () {
$(this).parent().next().toggle();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.