
jquery怎么选中以什么开头的元素?
在jquery中可以使用属性选择器[attribute^=value]来选中以什么开头的元素;"^="表示以什么开头。
[attribute^=value] 选择器选取每个带有指定属性且以指定字符串开头的元素。
语法
$("[attribute^='value']")参数:
attribute 必需。规定要查找的属性。
value 必需。规定属性值以其开头的字符串。
示例:选取所有带有以 "nation" 开头的 name 属性的 <input> 元素
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/jquery/1.10.2/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>选取所有 name 属性以 'nation' 为开头的 input 元素。</p>
</body>
</html>效果图:

更多web开发知识,请查阅 HTML中文网 !!
以上就是jquery怎么选中以什么开头的元素?的详细内容,更多请关注易知道|edz.cc其它相关文章!












