jQuery [attribute^=value] 选择器
实例
选择 name 属性以 "nation" 开头的所有 <input> 元素:
<!DOCTYPE html><html><head><script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script><script>$(document).ready(function(){$("input[name^='nation']").css("background-color", "yellow");});</script></head><body><input name="nationality" type="text" value="Chinese"><input name="nation" type="text" value="English"><input name="country" type="text" value="Germany"><input name="anothernation" type="text" value="Norwegian"><p>该选择器选择属性名称以 'nation' 开头的所有 input 元素。</p></body></html>
定义与用法
[attribute^=value] 选择器选择具有特定属性的每个元素,其值以特定字符串开头。
语法
$("[attribute^='value']")
| 参数 | 描述 |
|---|---|
| attribute | 必填。指定要查找的属性 |
| value | 必填。指定值应以开头的字符串 |