x
 
<!DOCTYPE html>
<html>
<body>
密码:<input type="password" id="myPsw">
<p>单击该按钮可设置密码字段中允许的最大字符数。</p>
<button onclick="myFunction()">试一试</button>
<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("myPsw").maxLength = "10";
  document.getElementById("demo").innerHTML = "密码字段中允许的最大字符数现在是 10。";
}
</script>
</body>
</html>