比如我有两个文本框,一个是城市,一个是区/县,那么我想城市输入北京的时候,区县文本框变成只读,而且值为北京,那么我输入上海的时候,区县文本框可编辑,求教大神
求大神给我解答一下 感激不尽 查了资料也没看出个所以然 谢谢
思路是输入市查询区/县,根据区/县判断区/县文本框是否只读
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" id="province">
<input type="text" id="county">
<script>
var county = document.getElementById("county");
var province = document.getElementById("province");
province.addEventListener("input",function(){
var val = this.value;
if (val == "北京"){
county.setAttribute("readonly","true");
county.value = "北京";
}else if (val == "上海"){
county.removeAttribute("readonly");
}
})
</script>
</body>
</html>