如何設置的minLength爲受到影響沒有其他的單個元素如何設置的minLength jQuery的組合框各個元素
編輯:
繼承人的插件代碼
(function ($) {
$.widget("ui.combobox", {
_create: function() {
var input,
self = this,
select = this.element.hide(),
selected = select.children(":selected"),
value = selected.val() ? selected.text() : "",
wrapper = this.wrapper = $("<span>")
.addClass("ui-combobox")
.insertAfter(select);
input = $("<input>")
.appendTo(wrapper)
.val(value)
.addClass("ui-state-default ui-combobox-input")
.autocomplete({
delay: 300,
minLength: 2,
source: function(request, response) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
response(select.children("option").map(function() {
var text = $(this).text();
if (this.value && (!request.term || matcher.test(text)))
return {
label: text.replace(
new RegExp(
"(?![^&;]+;)(?!<[^<>]*)(" +
$.ui.autocomplete.escapeRegex(request.term) +
")(?![^<>]*>)(?![^&;]+;)", "gi"
), "<strong>$1</strong>"),
value: text,
option: this
};
}));
},
select: function(event, ui) {
ui.item.option.selected = true;
self._trigger("selected", event, {
item: ui.item.option
});
},
change: function(event, ui) {
if (!ui.item) {
var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$", "i"),
valid = false;
select.children("option").each(function() {
if ($(this).text().match(matcher)) {
this.selected = valid = true;
return false;
}
});
if (!valid) {
// remove invalid value, as it didn't match anything
$(this).val("");
select.val("");
input.data("autocomplete").term = "";
return false;
}
}
}
})
.addClass("ui-widget ui-widget-content ui-corner-left");
input.data("autocomplete")._renderItem = function(ul, item) {
return $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.label + "</a>")
.appendTo(ul);
};
$("<a>")
.attr("tabIndex", -1)
.attr("title", "Show All Items")
.appendTo(wrapper)
.button({
icons: {
primary: "ui-icon-triangle-1-s"
},
text: false
})
.removeClass("ui-corner-all")
.addClass("ui-corner-right ui-combobox-toggle")
.click(function() {
// close if already visible
if (input.autocomplete("widget").is(":visible")) {
input.autocomplete("close");
return;
}
// work around a bug (likely same cause as #5265)
$(this).blur();
// pass empty string as value to search for, displaying all results
input.autocomplete("search", "");
input.focus();
});
},
destroy: function() {
this.wrapper.remove();
this.element.show();
$.Widget.prototype.destroy.call(this);
}
});
})(jQuery);
我正在選擇哪些選擇標籤必須製作成這樣的組合框。
$("#tracklisting").combobox({
selected: function(event, ui) {
var tracklisting = $("#tracklisting").val();
var id = $("#id").val();
$.post('writeToDB.php', {
id: id,
tracklisting: tracklisting
});
}
})
我在哪裏可以設置$("#tracklisting").autocomplete("option", "minLength", 0);
來設置長度。我已經嘗試了很多東西,但無濟於事。
編輯: 這是一個jsfiddle鏈接到項目。 COMBOX可以留在默認值,但combobox2必須爲0 http://jsfiddle.net/5cMjk/4/
您使用哪個jquery插件用於Combobox?在jsfiddle.net上創建一個工作演示? – codef0rmer 2012-08-16 11:54:25
@ codef0rmer JqueryUI 1.8.22 ui-combobox。這個簡單的插件使html選擇外觀和工作更好。下面是jqueryui網站http://jqueryui.com/demos/autocomplete/#combobox上確切內容的鏈接。我的代碼與javascrpit中的演示基本相同。 – Mark 2012-08-16 12:12:18
我沒有正確回答你的問題,你想達到什麼目的? – codef0rmer 2012-08-16 12:18:30