如何使用HTML存储页面或应用程序专用的自定义数据?
使用HTML中的data-*属性将私有数据存储在HTML页面中。它由属性组成,该属性不应包含任何大写字母,并且应在数据后添加前缀。
您可以尝试运行以下代码以实现data-*属性-
示例
<!DOCTYPE html>
<html>
<head>
<script>
function display(rank) {
var myRank = rank.getAttribute("data-rank-type");
alert("Rank " + rank.innerHTML + " has " + myRank + " points.");
}
</script>
</head>
<body>
<h1>Rank and Points</h1>
<p>Click on any rank to generate the details.:</p>
<ul>
<li onclick = "display(this)" id = "fifth" data-rank-type = "500">Fifth</li>
<li onclick = "display(this)" id = "sixth" data-rank-type = "600">Sixth</li>
</ul>
</body>
</html>