admin管理员组文章数量:1323225
I'm working on some plicated form at the moment.
Just wondering, is there any better way to do this:
$('.selector').each( function(){
$("input", this).prop('disabled', true);
$("select", this).prop('disabled', true);
$("label", this).prop('disabled', true);
$("textarea", this).prop('disabled', true);
});
I want to select all inputs within this
(currently looped through .selector
).
Am I doing this correctly?
I'm working on some plicated form at the moment.
Just wondering, is there any better way to do this:
$('.selector').each( function(){
$("input", this).prop('disabled', true);
$("select", this).prop('disabled', true);
$("label", this).prop('disabled', true);
$("textarea", this).prop('disabled', true);
});
I want to select all inputs within this
(currently looped through .selector
).
Am I doing this correctly?
- 1 Yes, technically. Although @BoltClock's answer below is a better way of doing this. – rossipedia Commented Nov 14, 2011 at 15:34
1 Answer
Reset to default 17That's fine, but to simplify it you should be able to use the ma as you would to group any other selectors:
$('.selector').each(function() {
$('input, select, label, textarea', this).prop('disabled', true);
});
If the only thing you're doing is setting that property on those elements, then you don't really need the .each()
loop. You can safely drop that and reduce it to this one-liner:
$('input, select, label, textarea', '.selector').prop('disabled', true);
本文标签: javascriptSelect all inputslabelsselects etc within THISeach loopStack Overflow
版权声明:本文标题:javascript - Select all inputs, labels, selects etc within THIS - each loop - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740072520a2223126.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论