Javascript 在divjQuery中有选择地设置多个输入的属性

Javascript 在divjQuery中有选择地设置多个输入的属性,javascript,jquery,html,Javascript,Jquery,Html,我的div包括类型select、文本输入、checkbox和各种其他输入 我已经成功地使用jQuery中下面的代码将div中所有元素的disabled属性设置为true $("#for_all_div1 :input").attr("disabled", true); $("#for_all_div2 :input").attr("disabled", true); 我的问题是如何为div中的所有输入设置属性,但跳过复选框输入 谢谢,如果要禁用除复选框之外的所有输入,请使用:not(:chec

我的div包括类型select、文本输入、checkbox和各种其他输入

我已经成功地使用jQuery中下面的代码将div中所有元素的disabled属性设置为
true

$("#for_all_div1 :input").attr("disabled", true);
$("#for_all_div2 :input").attr("disabled", true);
我的问题是如何为div中的所有输入设置属性,但跳过复选框输入


谢谢,

如果要禁用除复选框之外的所有输入,请使用
:not(:checkbox)

$(“#for_all_div2:not(:checkbox)”).prop(“disabled”,true)

此外,最好使用
.prop()
而不是
.attr()
来设置禁用属性

演示

$(“#for_all_div2:not(:checkbox)”).prop(“disabled”,true)

如果要禁用除复选框之外的所有输入,请使用
:not(:checkbox)

$(“#for_all_div2:not(:checkbox)”).prop(“disabled”,true)

此外,最好使用
.prop()
而不是
.attr()
来设置禁用属性

演示

$(“#for_all_div2:not(:checkbox)”).prop(“disabled”,true)

使用
.not()

$(“#for_all_div2:input”).not(“[type=checkbox]”)
.attr(“禁用”,真实)


使用
.not()

$(“#for_all_div2:input”).not(“[type=checkbox]”)
.attr(“禁用”,真实)



@DouglasHosea没问题,很乐意为您提供帮助p/s:您应该使用来设置属性,而不是
.attr()
@Terry true true,我刚刚复制了op的示例,必须承认我没有检查.attr。将更改它。@DouglasHosea没问题,很乐意提供帮助P/s:您应该使用来设置属性,而不是
.attr()
@Terry true true,我刚刚复制了op的示例,必须承认我没有检查.attr。我会改变的。