我试图结合bootstrap-select和jquery链接来过滤我的选择列表。她是我的代码
<select id="mark" name="mark" class="selectpicker" multiple>
<option value="">--</option>
<option value="bmw">BMW</option>
<option value="audi">Audi</option>
</select>
<select id="series" name="series" class="selectpicker" multiple>
<option value="">--</option>
<option value="series-3" class="bmw">3 series</option>
<option value="series-5" class="bmw">5 series</option>
<option value="series-6" class="bmw">6 series</option>
<option value="a3" class="audi">A3</option>
<option value="a4" class="audi">A4</option>
<option value="a5" class="audi">A5</option>
</select>
当我选择宝马和奥迪时。唯一出现的系列是宝马。我期待宝马和奥迪系列。这里是jsfield样本https://jsfiddle.net/80zkodod/。
/*! Chained 1.0.0 - MIT license - Copyright 2010-2014 Mika Tuupola */
!function (a, b) {
"use strict";
a.fn.chained = function (c) {
return this.each(function () {
function d() {
var d = !0;
a(e).html(f.html());
var h = a("option:selected", this).parent().val();
var arr = h.toString().split(",");
a("option", e).each(function () {
var current_class = a(this).attr("class");
if(h != current_class && $.inArray(current_class, arr) < 0){
a(this).remove()
}
});
if (1 === a("option", e).size() && "" === a(e).val()) {
a(e).prop("disabled", !0)
} else {
a(e).prop("disabled", !1)
}
d && a(e).trigger("change")
}
var e = this, f = a(e).clone();
a(c).each(function () {
a(this).bind("change", function () {
d()
}), a("option:selected", this).length || a("option", this).first().attr("selected", "selected"), d()
})
})
}, a.fn.chainedTo = a.fn.chained, a.fn.chained.defaults = {}
}(window.jQuery || window.Zepto, window, document);
将chained.js代码更改为此
样品小提琴