DOM基础及高级DOM
4.3.1 操纵HTML属性 在HTML代码编写中,读者一定都习惯了使用HTML的节点属性来控 制节点的行为。在下面的代码中,有一个水平条标记: <hr color="red" size="10" width="80%"></hr> 如果现在需要操作color、size属性,那么需要使用 setAttrinute()、getAttribute()方法。在以下代码中,演示了 如何更改color、size等属性: function modifyAttribute() { var hr=document.getElementById("hr"); alert(hr.getAttribute("color")); alert(hr.getAttribute("size")); hr.setAttribute("color","#0000ff"); hr.setAttribute("size","100"); }