close
<div id="mydiv" data-brand="toyota" data-model="prius">
John is very happy with his Toyota Prius, because he saves on gas.
</div>
//使用 DOM 的 getAttribute() 屬性 var brand = mydiv.getAttribute("data-brand");// 回傳 "toyota" mydiv.setAttribute("data-brand", "mazda"); // "data-brand" 變更為 "mazda" mydiv.removeAttribute("data-brand"); // 完整移除 "data-brand" 屬性
--
轉自 https://zetajames.wordpress.com/2009/12/14/html5-customattributes/
全站熱搜