<h1 id="h">test</h1>
var h1 = document.getElementById("h");
如果要添加 class="blue bold",有三种方法
1.
h.setAttribute("class","blue bold");
2.
h.setAttribute("className","blue bold");
3.
h.className = "blue bold";
第1种方法只支持firefox
第2种方法只支持IE
第3种方法两者都支持,且写法简洁,所以选用第3种方法
var h1 = document.getElementById("h");
如果要添加 class="blue bold",有三种方法
1.
h.setAttribute("class","blue bold");
2.
h.setAttribute("className","blue bold");
3.
h.className = "blue bold";
第1种方法只支持firefox
第2种方法只支持IE
第3种方法两者都支持,且写法简洁,所以选用第3种方法