我想选择一个带有两个 not 子句的特定节点,但到目前为止我还没有成功。我需要做的是,选择一个 div 包含字符串 0008 的元素,但它不是 10008,而且它不包含标签“style”,所以,理论上它应该像这样工作:
document.querySelectorAll(" div[id*='0008']:not([id='10008'][style])")
但是,正如您可能怀疑的那样,它并不是这样工作的。
document.querySelectorAll(" div[id*='0008']:not([id='10008'])")
document.querySelectorAll(" div[id*='0008']:not([style])")
当然,它们两个单独工作都完美。
最佳答案
not 10008 and also it does not …
这不是您当前选择器检查的内容,它测试它是否没有( id 和 style 属性)。改用这个:
div[id*='0008']:not([id='10008']):not([style])
您原来的解决方案也不是有效的选择器,因为 :not()
may only contain one simple selector ,而你有两个。然而,像 jQuery 的 sizzle 引擎这样的选择器库可能 support them 。因此,使用 jQuery,以下内容也可以工作:
div[id*='0008']:not([id='10008'],[style])
关于javascript - 多个 not() DOM 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14884843/