2016-05-15 55 views
0

形式输入字段的设置风格,如果我有一个形式保存的所有字段的数组,JS - 从阵列

var reqfield = document.getElementsByClassName("req"); 

如何设置单个字段的CSS样式基于所述阵列。

document.getElementById("myform")reqfield[1].style.backgroundColor = "red"; 
+0

只是删除从'的document.getElementById的'的document.getElementById( “myForm会”)'( “myForm会”)reqfield [1]',为什么呢?你有很多这个ID的元素? – Sergio

回答

1

您已经将项目存储在数组中。它应该只是

reqfield[1].style.backgroundColor = "red";