<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <input type="button" value="显示效果" id="bt"/><br/> <input type="text" value="你好" name="name1"/><br/> <input type="text" value="你好" name="name2"/><br/> <input type="text" value="你好" name="name3"/><br/> <input type="text" value="你好" name="name2"/><br/> <input type="text" value="你好" name="name4"/><br/> <input type="text" value="你好" name="name2"/><br/> <script> //点击按钮修改name属性为name2的value值 document.getElementByName("bt").onclick = function () { var texs = document.getElementsByName("name2"); for(var i = 0; i < texs.length; i++) { texs[i].value = "我不好"; } }; </script> </body> </html>
document.getElementsByName("")