Input Button valueProperty

Button 对象参考手册Button Object

Definition and Usage

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

The value attribute specifies the text displayed on the button.

Syntax

Setting the value property:

buttonObject.value="value"

Returning the value property:

buttonObject.value


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the value property


Example

Example

Display the text of the button:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
    var x=document.getElementById("button1").value;
    alert(x);
}
</script>
</head>
<body>

<form>
<input type="button" onclick="displayResult()" id="button1" value="Display button text">
</form>

</body>
</html>

Try it Yourself »


Button 对象参考手册Button Object Other Extensions