本文实例讲述了jQuery中[attribute]选择器用法。分享给大家供大家参考。具体分析如下:
此选择器能够匹配带有给定属性的元素。
语法结构:
$(\"[attribute]\")
参数列表:
参数 |
描述 |
attribute |
要查找的属性名称。 |
实例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset=\" utf-8\">
<meta name=\"author\" content=\"http://www.phpstudy.net/\" />
<title>phpstudy</title>
<script type=\"text/javascript\" src=\"mytest/jQuery/jquery-1.8.3.js\"></script>
<script type=\"text/javascript\">
$(document).ready(function(){
$(\"button\").click(function(){
$(\"[title]\").css(\"color\",\"blue\");
});
});
</script>
</head>
<body>
<ul>
<li id=\"first\">html专区</li>
<li id=\"second\" title=\"jquery\">Jquery专区</li>
</ul>
<ul>
<li id=\"third\">欢迎来到phpstudy</li>
<li>phpstudy欢迎您</li>
</ul>
<button>点击查看效果</button>
</body>
</html>
以上代码可以将具有title属性的li元素中的文本颜色设置为蓝色。
希望本文所述对大家的jQuery程序设计有所帮助。
本文地址:https://www.stayed.cn/item/2116
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我