我有一个包含多列的html表,在两列中我显示下拉列表 . 当用户从一个下拉列表中选择值时(选择Product1或Select Product2下拉列表),我想删除在一个下拉列表中选择的选项,并且不要在另一个下拉列表中显示该选项...
下面的示例代码适用于表中可用的所有下拉列表的类名相同(选择Product1,选择Product2),但在我的情况下,下拉列表的类名对于表中的每个列都是相同的,这打破了以下码 .
var $combo = $(".combo");
$combo.on("change", function () {
var select = this,
selected = $("option:selected", this).text();
$combo.each(function (_, el) {
if (el !== select) {
$("option", el).each(function (_, el) {
var $el = $(el);
if ($(el).text() === selected) {
$el.remove();
}
});
}
});
});
在上面的演示中,当用户从一行的下拉列表中选择产品“laptop”时,该行中存在的另一个下拉列表中不应显示“laptop”选项...