<html>
<body>
密码:<input type="password" id="myPsw">
<p>单击按钮可将密码字段设置为只读。</p>
<p><b>提示:</b>如需查看效果,请尝试在单击按钮前后在密码字段中键入内容。</p>
<button onclick="myFunction()">设置为只读</button>
<script>
function myFunction() {
document.getElementById("myPsw").readOnly = true;
}
</script>
</body>
</html>