Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 15:52:01
Original
3154 people have browsed it

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!