JS setAttribute 方法的非DOM解决方案

//将element对象的value属性的值 修改为 'the new value'
element.value = 'the new value';
//等价于
element.setAttribute('value','the new value')

setAttribute 的优势在于 可以修改文档中的任何一个元素的任何一个属性;

“第一级DOM”的另一个优势 可移植性更好 。(DOM是一种适用于多种环境和多种程序设计语言的通用型API ,兼容性强)

猜你喜欢

转载自www.cnblogs.com/hezhouhang/p/9154421.html