jQuery logojQuery API 中文文档 | jQuery 中文网

  • 首页
  • 下载jquery
  • jQuery 插件
  • 浏览器支持
  • 英文文档镜像

分类:属性选择器


The CSS specification allows elements to be identified by their attributes. While not supported by some older browsers for the purpose of styling documents, jQuery allows you to employ them regardless of the browser being used.

When using any of the following attribute selectors, you should account for attributes that have multiple, space-separated values. Since these selectors see attribute values as a single string, this selector, for example, $("a[rel='nofollow']"), will select <a href="example.html" rel="nofollow">Some text</a> but not <a href="example.html" rel="nofollow foe">Some text</a>.

Attribute values in selector expressions must follow the rules for W3C CSS selectors; in general, that means anything other than a valid identifier should be surrounded by quotation marks.

  • double quotes inside single quotes: $('a[rel="nofollow self"]')
  • single quotes inside double quotes: $("a[rel='nofollow self']")
  • escaped single quotes inside single quotes: $('a[rel=\'nofollow self\']')
  • escaped double quotes inside double quotes: $("a[rel=\"nofollow self\"]")

The variation you choose is generally a matter of style or convenience.

Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the "@" symbol from your selectors in order to make them work again.

选择器 > 属性选择器

Attribute Contains Prefix Selector [name|="value"]

选择指定属性值等于给定字符串或以该字符串为前缀(该字符串后跟一个连字符“-” )的元素。
选择器 > 属性选择器

Attribute Contains Selector [name*="value"]

选择指定属性具有包含一个给定的子字符串的元素。(选择给定的属性是以包含某些值的元素)
选择器 > 属性选择器

Attribute Contains Word Selector [name~="value"]

选择指定属性用空格分隔的值中包含一个给定值的元素。
选择器 > 属性选择器

Attribute Ends With Selector [name$="value"]

选择指定属性是以给定值结尾的元素。这个比较是区分大小写的。
选择器 > 属性选择器

Attribute Equals Selector [name="value"]

选择指定属性是给定值的元素。
选择器 > 属性选择器 | 选择器 > jQuery 扩展

Attribute Not Equal Selector [name!="value"]

选择不存在指定属性,或者指定的属性值不等于给定值的元素。
选择器 > 属性选择器

Attribute Starts With Selector [name^="value"]

选择指定属性是以给定字符串开始的元素
选择器 > 属性选择器

Has Attribute Selector [name]

选择所有具有指定属性的元素,该属性可以是任何值。
选择器 > 属性选择器

Multiple Attribute Selector [name="value"][name2="value2"]

选择匹配所有指定的属性筛选器的元素
  • Ajax
    • 全局 Ajax 事件处理器
    • 辅助函数
    • 底层接口
    • 快捷方法
  • DOM 属性
  • 回调对象
  • 核心 API
  • CSS
  • 数据操作
  • 延迟对象
  • 弃用
    • 1.3 版本弃用的 API
    • 1.4 版本弃用的 API
    • 1.7 版本弃用的 API
    • 1.8 版本弃用的 API
    • 1.9 版本弃用的 API
    • 1.10 版本弃用的 API
    • 3.0 版本弃用的 API
  • 尺寸
  • 特效
    • 基本特效
    • 自定义
    • 渐变
    • 滑动
  • 事件
    • 浏览器事件
    • 文档加载
    • 绑定事件处理器
    • 事件对象
    • 表单事件
    • 键盘事件
    • 鼠标事件
  • 表单
  • 内部函数
  • DOM 操作
    • class 属性
    • 复制元素
    • DOM 插入
    • DOM 插入并包裹现有内容
    • DOM 插入现有元素内
    • DOM 插入现有元素外
    • DOM 移除
    • DOM 替换
    • 通用属性操作
    • CSS 属性
  • 杂项
    • 集合操作
    • 数据存储
    • DOM 元素方法
    • 设置
  • 偏移
  • 内部属性
    • jQuery 对象实例的属性
    • 全局 jQuery 对象的属性
  • 已删除的函数
  • 选择器
    • 属性选择器
    • 基础选择器
    • 基础过滤
    • 子元素过滤
    • 内容过滤
    • 表单
    • 层级
    • jQuery 扩展
    • 可见性过滤
  • 遍历
    • 过滤
    • 其它遍历
    • 树遍历
  • 未归类
  • 工具类
  • 版本
    • 1.0 版本
    • 1.0.4 版本
    • 1.1 版本
    • 1.1.2 版本
    • 1.1.3 版本
    • 1.1.4 版本
    • 1.2 版本
    • 1.2.3 版本
    • 1.2.6 版本
    • 1.3 版本
    • 1.4 版本
    • 1.4.1 版本
    • 1.4.2 版本
    • 1.4.3 版本
    • 1.4.4 版本
    • 1.5 版本
    • 1.5.1 版本
    • 1.6 版本
    • 1.7 版本
    • 1.8 版本
    • 1.9 版本
    • Version 1.12 & 2.2
    • Version 3.0
    • Version 3.1
    • All
  • Bootstrap中文网
  • Node.js中文文档
  • Webpack中文网
  • NPM中文文档
  • SASS中文网
  • 全栈课堂
  • 91PHP

Copyright 2019 推荐使用阿里云 jQuery 中文网.