getElementsByClassName和setAttribute不起作用

时间:2013-03-19 22:01:01

标签: getelementsbyclassname

我正在尝试使用getElementsByClassName使用java脚本更改按钮的样式。它似乎不起作用。 Firebug给了我一个“没有足够的参数 - list [index] .setAttribute(”button“);”错误。

以下是我的代码:

function clear(y){
var list, index;
list = document.getElementsByClassName('button1);
for (index = 0; index < list.length; ++index) {
list[index].setAttribute("button");
}
}

非常感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:3)

错误是不言自明的。您缺少方法setAttribute()中的参数。为您想要新的button属性添加另一个参数。

list[index].setAttribute('button', 'myValue');

如果您打算删除button属性,请使用removeAttribute()

list[index].removeAttribute('button');
相关问题