js刪除樣式的方法:1、使用setAttribute()方法,語(yǔ)法“對(duì)象.setAttribute("屬性名稱","")”;2、使用removeProperty()方法,語(yǔ)法“對(duì)象.removeProperty("屬性名稱")”。
本教程操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。
javascript刪除css樣式
1、使用setAttribute方法清除樣式
<p id="p" style="color:#FF0000">hello world<p> <button onclick="myFunction()">點(diǎn)擊按鈕,去除樣式</button> <script> function myFunction() { document.getElementById("p").setAttribute('style', ''); } </script>
效果圖:
2、使用removeProperty方法
<p id="p" style="color:palevioletred;">hello world<p> <button onclick="myFunction()">點(diǎn)擊按鈕,去除樣式</button> <script> function myFunction() { document.getElementById("p").style.removeProperty("color"); } </script>
效果圖:
【推薦學(xué)習(xí):javascript高級(jí)教程】