我有两个输入字段,如果另一个输入字段中有值,我希望禁用另一个输入字段。我尝试使用 jQuery 但没有任何反应。有人知道我该怎么办吗?谢谢
我的输入框
<ul>
<li id="fixedSalaryList"><b>Fixed Salary (Monthly)</b>
<a href="#" class="show-input">$<?php echo $data['app1']['salary']; ?> <img src="<?php echo $dirimg; ?>/arrow-right.svg"></a>
<input type="text" name="salary[]" id="fixedSalary" class="assest-input inputNumber" value="<?php echo $data['app1']['salary']; ?>" inputmode="numeric">
</li>
<li id="selfEmployedList"><b>Self-Employed Income (Annually)</b>
<a href="#" class="show-input">$<?php echo $data['app1']['selfEmployedIncome']; ?><img src="<?php echo $dirimg; ?>/arrow-right.svg"></a>
<input type="text" name="selfEmployedIncome[]" id="selfEmployed" class="assest-input inputNumber" value="<?php echo $data['app1']['selfEmployedIncome']; ?>" inputmode="numeric">
</li>
</ul>
查询
$('input').on('input', function() {
$(this).closest('li').find('input').not(this).prop('disabled', this.value.length)
});
$('li input').on('input', function() {
$(this).closest('li').find('input').not(this).prop('disabled', this.value.length)
});
<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>
慕码人8056858
慕丝7291255
婷婷同学_