hasAttribute():判斷是否有某個自定義屬性
getAttribute():獲取自定義屬性 傳入屬性名
setAttribute():設置自定義屬性 傳入要設置的屬性名和屬性值
removeAttribute(): 傳入要刪除的屬性名
<div id="stu" name="lucy" age="15" height="758">王五</div>
<script type="text/javascript"> var oStu = document.getElementById('stu'); console.log(oStu.hasAttribute('name'));//判斷 var myAttr = oStu.getAttribute('age');//獲取 console.log(myAttr); oStu.setAttribute('age','18');//替換 console.log(oStu); oStu.removeAttribute('age');//刪除 console.log(oStu); oStu.setAttribute('class','mystyle'); </script>