विकल्प के गुणों को रखने के लिए लेसन का उत्तर अपडेट करें।
यह पहली बार स्टैक ओवरफ़्लो पर जवाब देने वाला है, इसलिए मुझे यकीन नहीं है कि मुझे अपना जवाब संपादित करना चाहिए या अपना खुद का बनाना चाहिए।
jQuery.fn.allAttr = function() {
var a, aLength, attributes, map;
if (!this[0]) return null;
if (arguments.length === 0) {
map = {};
attributes = this[0].attributes;
aLength = attributes.length;
for (a = 0; a < aLength; a++) {
map[attributes[a].name.toLowerCase()] = attributes[a].value;
}
return map;
} else {
for (var propin arguments[0]) {
$(this[0]).attr(prop, arguments[0][prop]);
}
return this[0];
}
};
jQuery.fn.filterByText = function(textbox) {
return this.each(function() {
var select = this;
var options = [];
$(select).find('option').each(function() {
options.push({ value: $(this).val(),
text: $(this).text(),
allAttr: $(this).allAttr() });
});
$(select).data('options', options);
$(textbox).bind('change keyup', function() {
var search = $.trim($(this).val());
var regex = new RegExp(search, "gi");
$.each($(select).empty().data('options'), function(i, option) {
if (option.text.match(regex) !== null) {
$(select).append(
$('<option>').text(option.text)
.val(option.value)
.allAttr(option.allAttr)
);
}
});
});
});
};
मैं इस लागू करने के लिए कोशिश कर रहा था, लेकिन यह पार ब्राउज़र संगत http://stackoverflow.com/questions/1271503/hide-options-in-a-select-list-using-jquery – James