文本框 `#test` 為空時,下拉框 `#sel1`、`#sel2` 禁用;輸入內容後啟用。
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(function() {
$("#test").on("input", function() {
var empty = $.trim(this.value) === "";
$("#sel1, #sel2").prop("disabled", empty);
}).trigger("input"); // 初始化觸發一次
});
</script>
</head>
<body>
<p>文本框為空時下拉框禁用</p>
<input id="test" type="text" />
<select id="sel1"><option>1</option><option>2</option></select>
<select id="sel2"><option>A</option><option>B</option></select>
</body>
</html>