<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>自定义标签属性值</title>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<style>
#one{
width: 150px;
height: 20px;
border: solid 1px black;
}
</style>
</head>
<body>
<div id="one" class="two" title="three">
six six six
</div>
<input id="four" value="five" />
<script>
var a = document.getElementById("four").value; //js取值
console.log("a = " + a);
var b = $("#four").val(); //jq取值
console.log("b = " + b);
var c = $("#one").html();
console.log("c = " + c);
var d = $("#one").attr("class"); //通过id取class属性值
console.log("d = " + d);
var e = $(".two").attr("title"); //通过class取title属性值
console.log("e = " + e);
$("#one").attr("class", "seven"); //通过id给class属性赋值
var f = $("#one").attr("class");
console.log("f = " + f);
</script>
</body>
</html>
自定义标签属性值
最新推荐文章于 2020-08-20 19:40:16 发布