简体   繁体   English

JS-从数组设置表单输入字段的样式

[英]JS - Set style of form input field from array

If i have saved all the fields in a form to an array, 如果我已将所有字段以表格的形式保存到数组中,

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

how can i set the css style of a single field based on said array. 我如何基于所述数组设置单个字段的CSS样式。

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

You've already got the item stored in the array. 您已经将项目存储在数组中。 It should just be 应该是

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM