Input Button nameProperty

Button 对象参考手册Button Object

Definition and Usage

The name property sets or returns the value of the name attribute of a button element.

The name attribute is used to transmit data to the server after form submission, or to reference form data in JavaScript.

Note:After form submission, only the name attribute of the form element will transmit the data value.

Syntax

Set the name attribute:

buttonObject.name="name"

Return the name attribute:

buttonObject.name


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the name attribute.


Examples

Examples

Display the name attribute value of the button:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.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="Display Name">
</form>

</body>
</html>

Try it Yourself »


Button 对象参考手册Button Object Other Extensions