标签data-*属性使用

时间:2024-03-22 17:04:44
<div class="page_index" style="margin-top:20px;">
<span id="showPage">第2页</span>
<span id="totalPage" data-size="4">共4页</span>
<a id="first" onclick="getPage(this)" href="javascript:void(0)"> message.first.page </a>
<a id="previous" onclick="getPage(this)" href="javascript:void(0)">[上一页] </a>
<a id="next" onclick="getPage(this)" href="javascript:void(0)"> [下一页] </a>
<a id="last" onclick="getPage(this)" href="javascript:void(0)"> message.last.page </a>
</div>

1,获取标签data-*属性值

var value = document.getElementById("totalPage").getAttribute("data-size");

2 ,设置标签data-*属性值

document.getElementById("totalPage").setAttribute("data-size",totalPage);