我有JavaScript代碼來禁用其他輸入,如果填充。 我需要在表中出來的數據庫。 可悲的是,它僅適用於第一個錶行和表禁用所有輸入(但如果輸入填充不是第一次什麼也不會發生)如果其中一個輸入填充,禁用表格行中的輸入
的Javascript:
$(function(){
$("input").on("keyup", function(){
if($(this).hasClass("inputA") && $(".inputA").val()){
$("input.inputB").prop("disabled", true);
$("input.inputA").prop("disabled", false);
$("input.inputC").prop("disabled", true);
} else if($(this).hasClass("inputB") && $(".inputB").val()){
$("input.inputA").prop("disabled", true);
$("input.inputB").prop("disabled", false);
$("input.inputC").prop("disabled", true);
} else if($(this).hasClass("inputC") && $(".inputC").val()){
$("input.inputA").prop("disabled", true);
$("input.inputB").prop("disabled", true);
$("input.inputC").prop("disabled", false);
} else {
$(".inputA, .inputB").prop("disabled", false);
}
});
});
從HTML表我的TD:
<td><input type="text" class="inputA" value=""></td>
<td><input type="text" class="inputB" value=""></td>
<td><input type="text" class="inputC" value=""></td>
如何讓它爲每行分開工作?
這是很好的例子,但這種禁止其他所有輸入表不只是在當前行 –
@IngusGraholskis檢查我的更新 – Alexis
很好的工作,它的工作原理和你做代碼這麼小!謝謝你:) –