禁用文本框.jpg
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
账号: <input type="text" value="传智你好..."/><button>禁用</button><button>解禁</button><br><br>
密码: <input type="password" value="aaabbbccc"/>
<script>
//需求:禁用文本框
//步骤:
//1.获取事件源和相关元素
//2.绑定事件
//3.书写事件驱动程序
//1.获取事件源和相关元素
var inp = document.getElementsByTagName("input")[0];
var btn1 = document.getElementsByTagName("button")[0];
var btn2 = document.getElementsByTagName("button")[1];
//2.绑定事件
btn1.onclick = function () {
//3.书写事件驱动程序
inp.disabled = "no";
}
btn2.onclick = function () {
//3.书写事件驱动程序
inp.disabled = false;
// inp.removeAttribute("disabled");
}
</script>
</body>
</html>