3 回答

TA貢獻1808條經驗 獲得超4個贊
你可以這樣做:
$(document).ready(function() {
$("#fixedSalary").on("input", function() {
if ($("#fixedSalary").val() != "") {
$("#selfEmployed").prop('disabled', true);
} else {
$("#selfEmployed").prop('disabled', false);
}
});
$("#selfEmployed").on("input", function() {
if ($("#selfEmployed").val() != "") {
$("#fixedSalary").prop('disabled', true);
} else {
$("#fixedSalary").prop('disabled', false);
}
});
});
$("#btnReset").click(function() {
$("#fixedSalary").prop('disabled', false);
$("#selfEmployed").prop('disabled', false);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li id="fixedSalaryList"><b>Fixed Salary (Monthly)</b>
<a href="#" class="show-input">$</a>
<input type="text" name="salary[]" id="fixedSalary" class="assest-input inputNumber" inputmode="numeric">
</li>
<li id="selfEmployedList"><b>Self-Employed Income (Annually)</b>
<a href="#" class="show-input">$</a>
<input type="text" name="selfEmployedIncome[]" id="selfEmployed" class="assest-input inputNumber" inputmode="numeric">
</li>
</ul>
<input type="submit" text="Reset" id="btnReset">

TA貢獻1871條經驗 獲得超8個贊
你可以通過這樣的change()活動來做到這一點
jQuery
$(document).ready(function(){
$("#selfEmployed").change(function(){
$("#fixedSalary").prop('disabled', true);
});
$("#fixedSalary").change(function(){
$("#selfEmployed").prop('disabled', true);
});
});
現在它將雙向工作。

TA貢獻1820條經驗 獲得超3個贊
這正是您正在尋找的
$(document).ready(function(){
$("#selfEmployed").keyup(function(){
if(!$("#selfEmployed").val()){
$("#fixedSalary").prop('disabled', false);
}
else {
$("#fixedSalary").prop('disabled', true);
}
});
$("#fixedSalary").keyup(function(){
if(!$("#fixedSalary").val()) {
$("#selfEmployed").prop('disabled', false);
}
else {
$("#selfEmployed").prop('disabled', true);
}
});
});
注意:請記住,我們是在keyup()活動中執行此操作的,因此即使您刪除輸入,它也會起作用。
添加回答
舉報