<html>
<body>
<input type="button" id="myBtn" name="myname" value="My Button">
<p>单击下面的按钮可显示和/或更改上面输入按钮的 name 属性的值。</p>
<button onclick="display()">显示名称</button>
<button onclick="change()">修改名称</button>
<script>
function display() {
var x = document.getElementById("myBtn").name;
alert("The name of the input button is: " + x);
}
function change() {
var x = document.getElementById("myBtn").name = "newButtonName";
alert ("The name was changed to: " + x);
}
</script>
</body>
</html>