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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2020-05-15 我要评论

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标签的所有属性的方法全部内容了,希望大家多多支持~

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们