Jas*_*son 1 html javascript jquery
我试图使用jquery禁用表单中的几乎所有输入元素,但我需要启用一些输入元素.例如:
$(document).ready(function () {
$("#document :input[name!='tloEnable']).attr("disabled", true);
});
Run Code Online (Sandbox Code Playgroud)
这对我所拥有的同名"tloEnable"的元素非常有用.但是,还有一些其他元素具有不同的名称属性(filename,notifyUsers,notifyTeam).如何在禁用剩余输入元素的同时包含它们?
$(document).ready(function () {
$("#document :input[name!='tloEnable], [name!='filename'], [name!='notifyUsers'], [name!='notifyTeam']).attr("disabled", true);
});
Run Code Online (Sandbox Code Playgroud)
使用.not() function和传递选择器; 匹配的元素将被排除在外:
$(document).ready(function () {
$(":input").not("[name=tloEnable], [name=filename], [name=notifyUsers]")
.prop("disabled", true);
});
Run Code Online (Sandbox Code Playgroud)
该:not() selector作品以同样的方式:
$(document).ready(function () {
$(":input:not([name=tloEnable], [name=filename], [name=notifyUsers])")
.prop("disabled", true);
});
Run Code Online (Sandbox Code Playgroud)