属性选择器

1.jQuery( “[attribute|=’value’]” )

等于给定字符以该字符串为前缀的元素。

<a href="example.html" hreflang="en">Some text</a> 
  <a href="example.html" hreflang="en-UK">Some other text</a>
  <a href="example.html" hreflang="english">will not be outlined</a>
$('a[hreflang|="en"]').css('border','3px dotted green');

将对第一个,第二个a标签添加边框。

2.jQuery( “[attribute*=’value’]” )

属性值中包含给定的值

3.jQuery( “[attribute~=’value’]” )

用空格分隔开的单词中包含给定值。

  <input name="man-news" />
  <input name="milk man" />
  <input name="letterman2" />
  <input name="newmilk" />
$('input[name~="man"]').val('选中的标签');

只对那么属性中单独的单词man的标签选中。

4.jQuery( “[attribute$=’value’]” )

给定值结尾的属性。

5.jQuery( “[attribute=’value’]” )

等于给定值

6.jQuery( “[attribute!=’value’]” )

反选不等于给定值的元素。
等同于 :not([attr=value])

7.jQuery( “[attribute^=’value’]” )

以给定字符串开始的元素。

8.jQuery( “[attribute]” )

选中具有指定属性的元素。

  <div>no id</div>
  <div id="hey">with id</div>
  <div id="there">has an id</div>
  <div>nope</div>
$('div[id]').one('click', function(){
  var idString = $(this).text() + ' = ' + $(this).attr('id');
  $(this).text(idString);
});
9.jQuery( “[attributeFilter1][attributeFilter2][attributeFilterN]” )
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值