<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>標題</title>
</head>
<body>
<!--表單元素 禁用,設置disabled屬性就可以了-->
<!--<input type="text" disabled="true"/>-->
<!--<input type="password" disabled="disabled"/>-->
<!--<input type="button" value="按鈕" disabled/>-->
<!--表單元素里面 disable屬性,還有checked屬性,還有selected屬性,他們設置上了是一種狀態,沒有設置上是另外一種狀態,那像這樣的屬性,如果要用js來設置的話,就給他們設置true或者false的值。-->
<!--<input type="checkbox"/><input type="checkbox" checked/>-->
<!--<br/><br/>-->
<!--<select name="" id="">-->
<!--<option value="">1</option>-->
<!--<option value="">2</option>-->
<!--<option value="" selected>3</option>-->
<!--</select>-->
<!--<br/><br/>-->
<!------------------------------------------------------------------>
<input type="text" />
<input type="password" />
<input type="button" value="按鈕" />
<button id="btnJY">禁用</button>
<button id="btnQY">啟用</button>
<script>
//1.如何用js來設置表單元素的禁用呢?
var btnJY = document.getElementById("btnJY");
var btnQY = document.getElementById("btnQY");
var inps = document.getElementsByTagName("input");
//2.給禁用按鈕設置單擊事件
btnJY.onclick = function () {
//給inps里面的每一個標簽,設置禁用。
for(var i = 0 ; i < inps.length; i++){
//如果html標簽里面設置了某種屬性是一種狀態,沒有設置這個屬性是另外一種狀態
//像這樣的屬性,如果想用js來設置,那么就給這個屬性設置true或者false的值。
inps[i].disabled = true;
}
}
//3.給啟用按鈕設置單擊事件
btnQY.onclick = function () {
//給每一個表單元素(inps)設置disable = false。
for(var i = 0 ; i < inps.length; i++){
inps[i].disabled = false;
}
}
</script>
</body>
</html>
