setAttribute
setAttribute 是一個DOM 方法,用來設定該DOM 的屬性值,其參數為setAttribute(屬性名稱, 屬性值)。
]document.getElmentById("test").setAttribute("onclick", "alert('test'); ");
雖然有些屬性值直接使用「=」來設定就行了,可是某些屬性值不允許這樣設定,因此還是多使用setAttribute 會比較好。
文章標籤
全站熱搜
setAttribute 是一個DOM 方法,用來設定該DOM 的屬性值,其參數為setAttribute(屬性名稱, 屬性值)。
]document.getElmentById("test").setAttribute("onclick", "alert('test'); ");
雖然有些屬性值直接使用「=」來設定就行了,可是某些屬性值不允許這樣設定,因此還是多使用setAttribute 會比較好。