What is wrong with this code? I have a multiselect (VendorIDs) and a select (vendorDropDown). I want to set a开发者_Python百科ll the selected items in VendorIDs to disabled in vendorDropDown. This doesn't work:
$('#Vendor_IDs :selected').each(function (i, selected) {
var v = $(selected).val();
$("#vendorDropDown option[value='" + v + "']").attr("disabled", true);
});
But, this does:
$('#Vendor_IDs :selected').each(function (i, selected) {
var v = $(selected).val();
alert(v);
$("#vendorDropDown option[value='" + v + "']").attr("disabled", true);
});
How does adding the alert change anything?
It looks like var v = $(selected).val();
takes too long to execute for the next line to be on time. Try this:
$('#Vendor_IDs :selected').each(function (i, selected) {
$("#vendorDropDown option[value='" + $(selected).val() + "']").attr("disabled", true);
});
This way, the second line is not dependent on the first line that was taking too long to execute. Let me know if it works.
-edited, 2nd try!-
$('#Vendor_IDs :selected').each(function() {
$("#vendorDropDown option[value='" + $(this).val() + "']").attr("disabled", true);
});
精彩评论