Method to get all properties of input tag
- 2021-07-01 06:23:36
- OfStack
1. Use jquery
$("input[name='btnAdd']").attr("value")
Obtain the value attribute value, and exchange other attributes for attr parameters to OK
2. Get by dots:
<!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>