<html>
<body>
<form>
密码:<input type="password" id="myPsw" name="pw">
</form>
<p>单击按钮以显示和/或更改密码字段的 name 属性的值。</p>
<button onclick="display()">显示名称</button>
<button onclick="change()">修改名称</button>
<script>
function display() {
var x = document.getElementById("myPsw").name;
alert("密码字段的名称是:" + x);
}
function change() {
var x = document.getElementById("myPsw").name = "newPasswordName";
alert ("名称已更改为:" + x);
}
</script>
</body>
</html>