我尝试应用此fiddle解决方案,但没有任何运气:(
$('.select').on('keyup change', function () {
var selected = [];
$(".select option:selected").each(function () {
if ($(this).val() !== "") selected.push($(this).val());
});
$(".select:not(this) option").each(function () {
if (selected.indexOf($(this).val()) > -1) $(this).prop("disabled", true);
else $(this).prop("disabled", false);
});
});
我想禁用以前选择的列表中的所有选定项目。
最佳答案
这不起作用,因为您要动态添加选择列表,并且要使用 keyup 和更改事件,您需要使用委托(delegate):
$(document).on('keyup change', '.select', function () {
var selected = [];
$(".select option:selected").each(function () {
if ($(this).val() !== "") selected.push($(this).val());
});
$(".select:not(this) option").each(function () {
if (selected.indexOf($(this).val()) > -1) $(this).prop("disabled", true);
else $(this).prop("disabled", false);
});
});
看 fiddle : https://jsfiddle.net/wfaaztnb/8/
关于javascript - Jquery 禁用选定的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36841230/