简体   繁体   English

如何使用jQuery选择具有属性和属性不等于特定值的元素?

[英]How to select element has attribute and attribute not equal to specific value using jquery?

I got the following line: 我得到以下行:

$("element").find("[attr!='val'][attr!='val'][attr!='val'][attr!='val'][attr!='val']") 

based on this answer. 基于答案。 My page stops running. 我的页面停止运行。 My assumption is that it finds all the different elements in the page, also the ones that don't have the attribute. 我的假设是,它会找到页面中所有不同的元素,以及没有该属性的元素。 Is that correct? 那是对的吗? If so how can I fix this? 如果可以,我该如何解决? I tried the 我尝试了

$("element").not("[attr='val']") 
// instead of 
$("element").find("[attr!='val']")

and it still crashed the page. 并且它仍然使页面崩溃。 The following code works of course: 下面的代码当然可以工作:

$("element").find("[attr='val']")

JQuery Has Attribute Selector [name] select element only has attribute without consider to it value. jQuery 具有属性选择器[name] select元素仅具有属性而不考虑其值。 You need to adding [attr] at the first of your selector. 您需要在选择器的第一个添加[attr]

 $("ul").find("[class][class!='A']").css("color", "red"); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul> <li class="A">A</li> <li class="A">A</li> <li class="B">B</li> <li>C</li> </ul> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用jquery选择具有&#39;abbr&#39;属性特定值的元素 - How can I select element that has specific value for 'abbr' attribute with jquery 如何使用jquery将css属性添加到具有特定属性的元素? - How to add css property to element has specific attribute using jquery? 如何查找具有特定属性且具有特定值的元素 - How to find an element with a specific attribute that has a specific value 如何使用jquery生成等于兄弟属性值的框? - How to generate box equal to sibling attribute value using jquery? 检查元素属性是否具有特定值JS - Check if element attribute has specific value JS 在javascript中选择具有特定属性值的节点 - Select a node that has a specific attribute value in javascript 我在这个Jquery代码中出错了什么,希望选择一个属性等于特定值的元素 - What am I getting wrong in this Jquery code, wishing to select an element where attribute is equal to particular value jquery:如何选择属性名称中包含数组值的复选框? - jquery: How to select the checkbox that has an array value in its attribute name? 如何在另一个属性中具有特定值的标签的 select 和 XML 属性值? - How to select an XML attribute value of a tag that has a specific value in another attribute? 如何通过jQuery对象的属性值获取特定元素? - How to get a specific element from a jQuery object by its attribute value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM