Home  >  Article  >  Web Front-end  >  JavaScript method to get and change the name attribute of the input tag_javascript tips

JavaScript method to get and change the name attribute of the input tag_javascript tips

WBOY
WBOYOriginal
2016-05-16 15:52:013154browse

The example in this article describes how to obtain and change the name attribute of the input tag using JavaScript. Share it with everyone for your reference. The specific implementation method is as follows:

<input name="kk"></input>

<script language="javascript">
// 这里用getElementsByTagName把所有的input对象取出来,
//这是这个问题的关键性的地方,用ByTagName而不是ByName。
var list = document.getElementsByTagName("input");
// 循坏这个集合,包括了所有的input。
var inputList = document.getElementsByName("kk");
//测试
for(i=0;i<list.length;i++){
// 这里弹出的就是'kk',当然也可以根据需要输出别的。
//比如:list[i].id; list[i].value等等。
alert(list[i].name);// 这是修改这个值
list[i].name = 'mm';// 这时弹出的就是'mm'了
alert(list[i].name);
}
</script>

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn