时间:2022-06-12 09:34:43 | 栏目:JavaScript代码 | 点击:次
1.用jquery
$("input[name='btnAdd']").attr("value")
获取value属性值,其它属性换attr的参数就OK
2.通过点来获取:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form id="form1" name="form1"> <input name="n1" type="text" /> <input name="n3" type="text" /> <input name="n4" type="text" /> </form> <script> window.onload = function(){ var inputs = document.form1.getElementsByTagName("input"); for(var i = 0; i < inputs.length; i++) { inputs[i].onclick = function(){ alert(this.name); }; } }; </script> </body> </html>