我试图禁用jquery中的所有元素的所有子元素。
打电话
$('#id_of_an_element').children().do(function(){ do_something; });
递归地调用一个元素的所有子元素,或者只对an_element的所有直接后代执行do_something?
帮助是赞赏,
玩笑
解决方法
Given a jQuery object that represents
a set of DOM elements,the .children()
method allows us to search through the
immediate children of these elements
in the DOM tree and construct a new
jQuery object from the matching
elements. The .find() and .children()
methods are similar,except that the
latter only travels a single level
down the DOM tree. Note also that like
most jQuery methods,.children() does
not return text nodes; to get all
children including text and comment
nodes,use .contents().
http://api.jquery.com/children/
如果您想在任何嵌套级别对所有后代采取行动,可以执行此操作:
$('#id_of_an_element').find('*').attr('disabled',true);
或使用后代选择器:
$('#id_of_an_element *').attr('disabled',true);
原文地址:https://www.jb51.cc/jquery/182127.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。