<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
ul {
list-style-type: none;
cursor: pointer;
}
</style>
</head>
<body>
<ul>
<li score="60">張三的數學成績</li>
<li score="90">趙四的數學成績</li>
<li score="90">王五的數學成績</li>
<li score="80">唐七的數學成績</li>
<li score="50">宋八的數學成績</li>
</ul>
<script src="common.js"></script>
<script>
var list = document.getElementsByTagName("li");
for (var i = 0; i < list.length; i++) {
list[i].onclick = function () {
// alert(this.score);//彈出undefined
alert(this.getAttribute("score"));
};
}
</script>
</body>
<input type="button" value="移除自定義屬性" id="btn" />
<div id="dv" score="80分" class="cls"></div>
<script src="common.js"></script>
<script>
my$("btn").onclick = function () {
// my$("dv").removeAttribute("score");
// my$("dv").className = "";
//也可以移除元素的自帶的屬性
my$("dv").removeAttribute("class");
};
</script>