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标签的所有属性
关键词: