Jel*_*lle 2 html javascript css jquery
我的HTML页面中有5个选择框,我正在尝试禁用已选中的其他选择框中的所有选项,取消选择它们时也必须重新启用它们.
到目前为止,我得出了这个结果:点击此处查看JSFiddle
使用这个JQuery
$('.poli').on('keyup change', function () {
$(this)
.siblings('select')
.children('option[value=' + this.value + ']')
.attr('disabled', true)
.siblings().removeAttr('disabled');
});
Run Code Online (Sandbox Code Playgroud)
然而,这不能很好地工作,它当时只选择和禁用1个选项...
有解决方案吗
你可以使用:
$('.poli').on('keyup change', function () {
var selectedValues = $('.poli').find('option:selected').map(function () {
return this.value ? this.value : null;
});
$('.poli').filter(function () {
return !this.value
}).find('option').each(function () {
$(this).prop('disabled', ~$.inArray(this.value, selectedValues));
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83 次 |
| 最近记录: |