1. 程式人生 > >JS setAttribute 方法的非DOM解決方案

JS setAttribute 方法的非DOM解決方案

pre setattr 適用於 col clas 設計 element 程序設計語言 code

//將element對象的value屬性的值 修改為 ‘the new value‘
element.value = ‘the new value‘;
//等價於
element.setAttribute(‘value‘,‘the new value‘)

setAttribute 的優勢在於 可以修改文檔中的任何一個元素的任何一個屬性;

“第一級DOM”的另一個優勢 可移植性更好 。(DOM是一種適用於多種環境和多種程序設計語言的通用型API ,兼容性強)

JS setAttribute 方法的非DOM解決方案