【发布时间】:2021-10-05 18:23:04
【问题描述】:
我有 2 个下拉菜单
当下拉 1 选项被选中时,它应该禁用下拉 2 选项,这样您就无法选择它
这是我的代码
<div class="form-group">
<label for="from_account">From Account:</label>
<select class="form-control" name="from_account" id="selectBox1" onchange="checkvalue1()">
<option disabled selected>Transfer From Account</option>
@foreach($accounts as $account)
<option value="{{$account->id}}">{{$account->account_number}} {{$account->account_name}} R{{$account->current_balance}}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="to_account">To Account:</label>
<select class="form-control" name="to_account" id="selectBox2" onchange="checkvalue2()">
<option disabled selected>Transfer To Account</option>
@foreach($accounts as $account)
<option value="{{$account->id}}">{{$account->account_number}} {{$account->account_name}} R{{$account->current_balance}}</option>
@endforeach
</select>
</div>
这是我的 JS
function checkvalue1(){
$("#selectBox2 option").each(function(){
if($("#selectBox1 option:selected").val() == $(this).val())
$(this).attr("disabled", "disabled");
else
$(this).removeAttr("disabled");
});
}
function checkvalue2(){
$("#selectBox1 option").each(function(){
if($("#selectBox2 option:selected").val() == $(this).val())
$(this).attr("disabled", "disabled");
else
$(this).removeAttr("disabled");
});
}
我让它以一种奇怪的方式工作,它有点错误,我需要帮助!
让我解释一下
如果我选择下拉菜单 1,它会禁用下拉菜单 2 中的选项,但它也允许我选择我从一开始就禁用的选项。
然后我需要它有点像切换,所以如果我选择帐户 1,例如它应该在它们之间切换,因为现在我必须选择其他内容或刷新页面,然后我才能单击另一个选项来选择我希望它使sense
【问题讨论】:
标签: javascript jquery laravel dropdown