如果用戶開始在input1中輸入一個值,我想禁用input2。如果另一個字段有一個值(動態),使用jquery禁用一個字段
如果input1中沒有值(例如,如果值被刪除),我還希望重新啓用input2。
這是我到目前爲止寫的,但它不工作。
<input id="input1" type="text">
<input id="input2" type="text">
<script>
$(document).ready(function() {
if($('#input1').val())
{
$('#input2').prop('disabled', true);
}
});
</script>
'propertychange'部分是做什麼的? 「輸入」事件不足以涵蓋打字,複製/粘貼等內容?請注意,如果你熱衷於簡潔的代碼,你可以用'secondInput.prop('disabled',event.currentTarget.value!=「」);' – nnnnnn
替換if/else,我。謝謝! – kevinkt
@nnnnnn接受了關於一班輪的建議。 propertychange是IE垃圾。有所有的瀏覽器,還有IE瀏覽器。我討厭IE。 – Bharel