因此,这里是自定义下拉列表的HTML,它不使用select标记。下拉列表的占位符/默认值为" Acura",这是列表中的第一个元素(ul)。我试图看看是否可以更改下拉列表的占位符/默认值(例如,宝马),而不更改下拉列表的顺序(品牌按字母顺序排列)。
<span id="builder-make-selection" class="pick">
<span class="label">Make:</span>
<div class="custom-dd-wrapper builder-makes" tabIndex="1">
<div class="custom_dd_select">
<span>
<a>Acura</a></span>
</div>
<div class="custom_dd_options">
<ul class="custom_dropdown">
<li data-make="Acura">Acura</li>
<li data-make="Alfa Romeo">Alfa Romeo</li>
<li data-make="Audi">Audi</li>
<li data-make="BMW">BMW</li>
</ul>
</div>
这是创建下拉列表的JavaScript:
(function(h, a) {
function k() {
var b = a(this).parents("div.custom_dd_wrapper"),
f = b.attr("id"),
e = a(b).find(".custom_dd_select a"),
l = a(this).data(),
d = e.text().trim(),
g = a(this).text().trim();
"makes-options" == f && (a(b).addClass("active"), e.parent("span").attr("style", a(this).attr("style")));
e.text(g);
for (var m in l) {
if(m=='make'){
e.parent("span").data(m,l[m]);
}
}
d != g && a(this).closest(".custom_dd_wrapper").trigger("change")
}
function g() {
var b = a(this).closest(".custom_dd_wrapper");
a(b).find("ul").hide();
a(b).find(".custom_dd_select").removeClass("click");
a(b).find(".custom_dd_options").removeClass("show")
}
h.CustomDropdownView = function() {
var b = this;
this.vc = !1;
a(".cs").on("click", ".trans-disabled", function(a) {
a.stopPropagation()
});
a(".cs").on("click", ".custom_dd_wrapper, .popup .custom_dd_wrapper", function() {
b.vc = !0;
var f = a(this).closest(".custom_dd_wrapper");
a(f).find("ul").toggle();
a(f).find(".custom_dd_select").toggleClass("click");
a(f).find(".custom_dd_options").toggleClass("show")
});
a(".cs").on("click", ".custom_dd_options .custom_dropdown > li:not(.trans-disabled)",
k);
if (0 > window.navigator.userAgent.indexOf("MSIE ") && null == navigator.userAgent.match(/Trident.*rv\:11\./)) a(".cs").on("blur", ".custom_dd_wrapper, .popup .custom_dd_wrapper", function() {
a(this).find(".custom_dd_options ul").is(":visible") && g.call(this)
});
else a(".cs").on("click", function() {
if (b.vc) b.vc = !1;
else {
var f = a(".custom_dropdown").filter(":visible");
0 < f.length && f.each(g);
}
});
a(".cs").on("click", ".disable", g)
}
})
答案 0 :(得分:0)
你必须改变
<div class="custom_dd_select">
<span>
<a>BMW</a></span>
</div>
到
{{1}}
那将有效