setAttribute

setAttribute 是一個DOM 方法,用來設定該DOM 的屬性值,其參數為setAttribute(屬性名稱, 屬性值)。

]document.getElmentById("test").setAttribute("onclick", "alert('test'); "); 

 

雖然有些屬性值直接使用「=」來設定就行了,可是某些屬性值不允許這樣設定,因此還是多使用setAttribute 會比較好。

文章標籤
全站熱搜
創作者介紹
創作者 GPhettoH 的頭像
GPhettoH

歇息,等待明日的天空

GPhettoH 發表在 痞客邦 留言(0) 人氣(0)