获取input标签的所有属性的方法

前端技术 2023/09/02 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>

以上就是小编为大家带来的获取input标签的所有属性的方法全部内容了,希望大家多多支持phpstudy~

本文地址:https://www.stayed.cn/item/4183

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。