星空网 > 软件开发 > Java

获取input标签的所有属性

1.用jquery
$("input[name='btnAdd']").attr("value")   

获取value属性值,其它属性换attr的参数就OK

 例:

 

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src='/images/loading.gif' data-original="jquery.js"></script>
</head>
<body>
<div >
<span>点击按钮获取文本框的name属性值:</span><br>
<div >
<input type="text" name="test" value="这个文本框的name属性值为test">
</div>
<input type="button" value="获取文本框name值">
</div>
<script>
$(function(){
$("input:button").click(function() {
alert($("input:text").attr("name"));
});
})

 

</script>
</body>
</html>

 

 

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标签的所有属性

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

亚马逊BestSeller操盘手分享的这六点,你都get了吗?:https://www.ikjzd.com/articles/111628
全球移动购物江湖:一场95后的争夺战!:https://www.ikjzd.com/articles/111629
新手卖家如何做到一年时间从月亏2万到月赚3万?:https://www.ikjzd.com/articles/111630
刺激黑五新客户复购的关键性因素是什么?:https://www.ikjzd.com/articles/111631
虾皮shopee全面讲解,从开店到运营,必看干货系列!:https://www.ikjzd.com/articles/111632
预警!冒充英国税务局诈骗进高峰期 !:https://www.ikjzd.com/articles/111633
2024.03.29亚马逊选品推荐(仅供参考):宠物饮水机滤芯片:https://www.kjdsnews.com/a/1836532.html
想要搞钱,就去做离搞钱最近的事:https://www.kjdsnews.com/a/1836533.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流