jquery – 递归禁用元素的所有子元素

这可能是一个是/否类型的问题。

我试图禁用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);

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...