读书人

搜索下级dom对象并隐藏点击隐藏父元

发布时间: 2012-10-07 17:28:51 作者: rapoo

搜索上级dom对象并隐藏,点击隐藏父元素
类似页面如下:

<tr>  <td><input type="checkbox" /></td>  <td><div name="code">$("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);});

读书人网 >Web前端

热点推荐