11jquery操作标签的其它属性和自定义属性

<head>
<meta charset="UTF-8">
<title>5.操作标签的其它属性和自定义属性.html</title>
</head>
<body>
<div role="role" title="标题" index="">测试标签属性</div>
<div>
<input type="button" value="获取标签属性:role">
<input type="button" value="获取标签属性:title">
<input type="button" value="为获取标签属性:role赋值">
<input type="button" value="为获取标签属性:title赋值">
<input type="button" value="获取标签自定义属性:index">
</div>
<hr>
<div id="show"></div>

</body>
<script src="js/jquery-1.8.3.js"></script>
<script>
$(":button:eq(0)").on("click",function () {
$("#show").html($("div :eq(0)").attr("role"));
})
$(":button:eq(1)").on("click",function () {
$("#show").html($("div :eq(0)").attr("title"));
})
$(":button:eq(2)").on("click",function () {
$("div :eq(0)").attr("role","role1");
})
$(":button:eq(3)").on("click",function () {
$("div :eq(0)").attr("title","title1");
})
$(":button:eq(4)").on("click",function () {
$("#show").html($("div :eq(0)").attr("index")?$("div :eq(0)").attr("index"):"未定义");
})
</script>
posted on 2022-04-17 15:32  小小程序猿level1  阅读(127)  评论(0)    收藏  举报