运行成果如下,
代码如下,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Dom对象</title>
<script>
window.οnlοad=function(){
var display=document.getElementById("display");
display.οnchange=function(){
var pwd=document.getElementById("pwd");
if(display.checked){
pwd.type="text";
}else{
//pwd.type="password";
pwd.setAttribute("type","password");
}
}
}
</script>
</head>
<body>
<form>
用户名<input type="text" name="name" id="name">
<br>
密码<input type="password" name="pwd" id="pwd" checked="true">
<br>
<input type="checkbox" name="display" id="display">显示密码
</form>
</body>
</html>