setAttribute(字符串,字符串值):添加指定的名称和值的一种新的属性,或者设置一个现有的属性指定的值。
1、风格问题
在setAttribute(班
的vname代表风格的分配。
例如:
复制代码代码如下所示:
无功输入= document.createelement(输入);
input.setattribute(类型
input.setattribute(名
input.setattribute(班

输出,即输入控制有bordercss样式属性
注意:类属性在W3C DOM中起着非常重要的作用,但由于浏览器的差异,它仍然存在。
使用setAttribute(阶级因为使用IE内核的浏览器不能识别阶级
以同样的方式,Firefox不知道类名,常用的方法是两:
复制代码代码如下所示:
element.setattribute(班
element.setattribute(名

2、方法属性和其他问题
例如:
复制代码代码如下所示:
VaR吧= document.getelementbyid(testbt );
bar.setattribute(onclick

这里我们使用setAttribute指定的onclick属性,简单的了解。
但IE不支持IE,而不是将不支持此功能,但不支持某些属性集的属性,如对象的属性,属性,属性集的事件,即风格和onclick这些属性设置在IE.使用将是不可能的
为了实现各种浏览器的兼容效果,可以通过点表示法设置元素的对象属性、集合属性和事件属性。
复制代码代码如下所示:
document.getelementbyid(testbt)。类名=bordercss ;
document.getelementbyid(testbt )。style.csstext =颜色:# 00f;;
document.getelementbyid(testbt )。style.color =# 00f ;
document.getelementbyid(testbt)。Onclick =函数(){ alert(这是一个测试!;}