JS 的替代方案是什么.not()
来自 jQuery?我有$(".form :input").not
,但需要将其转移到纯JS。有指南可以帮助我吗?
var input = $(".form :input").not('button, [type="button"], [type="submit"]').on({
input: return
});
我想在 JS 中做到这一点
现代浏览器确实支持NOT中的条款querySelectorAll()
:
document.querySelectorAll(".form :input:not(...)");
例子 (jsFiddle http://jsfiddle.net/HM7xd/2/):
<div>This should be colored!</div>
<div>This should be colored!</div>
<div id="this-not">This must not colored!</div>
<div>This should be colored!</div>
<div>This should be colored!</div>
var matchedElements = document.querySelectorAll("div:not(#this-not)");
for (var i=0; i<matchedElements.length; i++) {
matchedElements.item(i).style.backgroundColor = "red";
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)