Home >php教程 >PHP开发 >Detailed explanation of attribute filter selector of jquery selector

Detailed explanation of attribute filter selector of jquery selector

高洛峰
高洛峰Original
2016-12-17 15:58:411278browse
46d5fe1c7617e3914f214aaf043f4ccf
  /*高亮显示*/
  .highlight{   
   background-color: gray
  }
 531ac245ce3e4fe3d50054a55f265927
6c04bd5ca3fcae76e30b72ad730ca86d
   dc6dce4a544fdca2df29d5ac0ea9906b
      e388a4556c0f65e1904146cc1a846beeHello94b3e26ee717c64999d7867364b1b4a3
   16b28748ea4df4d9c2150843fecfba68
   c90ef46644c27e75cab5f1ef5a0f28c8ID为test的DIV16b28748ea4df4d9c2150843fecfba68
   4fb65521dabebd29be5be8a3a084f743足球
   e70f87b21cc1adba400eaae9c44a896a排球
   33fd076a5ca6b7d059888efe861853b1篮球
   ebfe6342499c93420dd9dd5327d0d971其他
  36cc49f0c466276486e50c850b7e4956

[attribute] Usage
Definition: Match elements that contain the given attribute

$("div[id]").addClass("highlight"); //查找所有含有ID属性的div元素

2. [attribute=value] Usage
Definition: Match elements where the given attribute is a specific value

$("input[name='basketball']").attr("checked",true);   //name属性值为basketball的input元素选中

3. [attribute! =value] Usage
Definition: Match the given attribute is an element that does not contain a specific value

$("input[name!='basketball']").attr("checked",true);   //name属性值不为basketball的input元素选中 
//此选择器等价于:not([attr=value])要匹配含有特定属性但不等于特定值的元素,请使用[attr]:not([attr=value])
$("input:not(input[name='basketball'])").attr("checked",true);

4. [attribute^=value] Usage
Definition: Match the given attribute is an element that starts with a certain value

$("input[name^='foot']").attr("checked",true);  //查找所有 name 以 'foot' 开始的 input 元素

5. [attribute$=value] Usage
Definition: Match the given attribute that ends with some value

$("input[name$='ball']").attr("checked",true); //查找所有 name 以 'ball' 结尾的 input 元素

6. [attribute*=value] Usage
Definition: Match the given attribute that ends with a certain value Elements of certain values

$("input[name*='sket']").attr("checked",true);  //查找所有 name 包含 'sket' 的 input 元素

7. [selector1][selector2][selectorN] Usage
Definition: Composite attribute selector, used when multiple conditions need to be met at the same time

$("input[id][name$='ball']").attr("checked",true);  //找到所有含有 id属性,并且它的 name属性是以 ball结尾的



More jquery selectors For detailed explanation of the attribute filter selector, please pay attention to the PHP Chinese website for related articles!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:jQuery selector summaryNext article:jQuery selector summary