如果在一个多选中选择了选项,请在另一个下拉列表中将其设置为禁用
这段代码有什么问题?我有一个多选(VendorIDs)和一个选择(vendorDropDown)。我想在vendorDropDown 中将VendorIDs 中的所有选定项目设置为禁用。这行不通:
$('#Vendor_IDs :selected').each(function (i, selected) {
var v = $(selected).val();
$("#vendorDropDown option[value='" + v + "']").attr("disabled", true);
});
但是,这行得通:
$('#Vendor_IDs :selected').each(function (i, selected) {
var v = $(selected).val();
alert(v);
$("#vendorDropDown option[value='" + v + "']").attr("disabled", true);
});
添加警报会如何改变什么?
What is wrong with this code? I have a multiselect (VendorIDs) and a select (vendorDropDown). I want to set all 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来
var v = $(selected).val();
需要很长时间才能按时执行下一行。试试这个:这样,第二行就不会依赖于执行时间太长的第一行。让我知道它是否有效。
-已编辑,第二次尝试!-
It looks like
var v = $(selected).val();
takes too long to execute for the next line to be on time. Try this: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!-