ITeye博客

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

夜鸣猪 · 2011-05-21 02:33 · javascript Jquery ext prototype · Web前端 · Java · Ruby · UP · Markdown

类似页面如下: [code="java"]

text to hide 1

text to hide 2

[/code] [code="java"]$("input.chk").click(function(){ $(this).parent().parent().(".disabled").show(); }) ;[/code] 实际使用.closest() 和 .find()更合适 [code="java"]$("input.chk").click(function(){ $(this).closest('tr').find(".disabled").show(); });[/code] 当然也可以 [code="java"]$(this).parent().parent().find(".disabled").show();[/code] 如果,有多行的话用.delegate()如下: [code="java"]$("table").delegate("input.chk", "click", function(){ $(this).closest('tr').find(".disabled").show(); });[/code] [code="ruby"] #.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); });[/code]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。