Javascript的Attribute和setAttribute

首先讲讲setAttribute,我们经常需要在JavaScript中给Element动态添加各种属性,这可以通过使用setAttribute()来实现,这就涉及到了浏览器的兼容性问题。

setAttribute(string name, string value):

//增加一个指定名称和值的新属性,或者把一个现有的属性设定为指定的值。

1、样式问题
setAttribute(“class”, value)中class是指改变”class”这个属性,所以要带引号。
vName代表对样式赋值。

阅读更多