搜索上级dom对象并隐藏,点击隐藏父元素

类似页面如下:

<tr>
<td><input type="checkbox" class="chk" /></td>
<td><div class="disabled">text to hide 1</div></td>
<td><div class="disabled">text to hide 2</div></td>
</tr>



$("input.chk").click(function(){
$(this).parent().parent().(".disabled").show();
}) ;


实际使用.closest() 和 .find()更合适
$("input.chk").click(function(){
$(this).closest('tr').find(".disabled").show();
});

当然也可以

$(this).parent().parent().find(".disabled").show();


如果,有多行的话用.delegate()如下:

$("table").delegate("input.chk", "click", function(){
$(this).closest('tr').find(".disabled").show();
});




#.delegate() instead binds one handler to the table for all of the input.chk elements to bubble up to. If you're looking to enable/disable, use hcnage and .toggle() in addition to the above, like this:
$("table").delegate("input.chk", "change", function(){
$(this).closest('tr').find(".disabled").toggle(this.checked);
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值