JQuery:模糊匹配html属性

jQuery("[attribute |= value]")

属性字头选择器(attribute contains prefix selector)

如jQuery("[herflang |= 'en']")这句代码执行时将会选择文档中所有含有herflang属性,并且herflang的值以“en”开头的元素,即使"en"后面紧跟着连字符"-"也能进行选择。

jQuery("[attribute ^= value]")

属性开头选择器(attribute starts with selector)

用于选择属性的值以某个字符串开头的元素,但和jQuery("[attribute] = value")的区别是,如果value的后面是一个连字符,这个元素不会被选择。例如jQuery("[rel ^= 'no']")将会选择所有rel的值以‘no’开头的元素,但类似于rel='no-***'的元素不会被选择。

jQuery("[attribute *= value]")

属性包含选择器(attribute contains selector)

例如jQuery("rel *= 'no'"),表示所有带有rel属性,并且rel的值里包含子字符串“no”的元素(如rel="nofollow", rel = "yesorno"等等)都将会被选择。

jQuery("attribute ~= value")

属性单词选择器(attribute contains word selector)

value的值必需是一个独立的单词或字符串,例如jQuery("rel ~= no"),此句在执行的时候会选择带有rel="yes or no"的元素,但不会选择带有rel = "yesorno" 的元素。这个选择器可以看做属性包含选择器的补充品,用于需要进行严格匹配的时候

jQuery("[attribute $= value]")

属性结尾选择器(attribute ends with selector)

用于选择特定属性的值以某个字符串结尾的元素,例如jQuery("[rel $= 'no']")将会选择rel属性的值以“no”结尾的元素

jQuery("[attribute = value]")

属性均等选择器(attribute equals selector)

只选择属性的值完全相等的元素,差一点都不行

jQuery("attribute != value")

属性非等选择器(attribute not equal selector)

选择属性不等于某个值的元素,例如jQuery("[rel != nofollow]"),所有rel = "nofollow"的元素都不会被选择

 

posted @ 2016-05-12 11:28  Carolina  阅读(515)  评论(0编辑  收藏  举报