HTML DOM Input Button name attribute
Definition and Usage
name property sets or returns the name attribute value of the button element.
name attribute is used after the form is submitted to the server to transmit data or form data referenced in Javascript.
Note: After the form is submitted only name attribute of the form element will pass data values.
grammar
Setting name attribute:
buttonObject.name="name"
Returns the name attribute:
buttonObject.name
Browser Support
All major browsers support attribute name
Examples
Examples
Button name attribute value display button:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var x=document.getElementById("button1").name;
alert(x);
}
</script>
</head>
<body>
<form>
<input type="button" onclick="displayResult()" id="button1" name="button1" value="显示名称">
</form>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
var x=document.getElementById("button1").name;
alert(x);
}
</script>
</head>
<body>
<form>
<input type="button" onclick="displayResult()" id="button1" name="button1" value="显示名称">
</form>
</body>
</html>
try it"
Button Objects