gpt4 book ai didi

javascript - 所选下拉菜单的模糊逻辑

转载 作者:行者123 更新时间:2023-12-03 10:27:35 25 4
gpt4 key购买 nike

我有一把 fiddle 。

http://jsfiddle.net/jHvmg/318/

$(document).ready(function () {
$('#campaign_list').chosen({
no_results_text: "Oops, nothing found!"
});
$('#campaign_list').css({
'width': '100%',
'height': '30px',
'border-radius': '2px'
});
$('#campaign_list_chosen').css({
'width': '100%',
'height': '30px',
'border-radius': '2px'
});
$('#camp_list').chosen({
no_results_text: "Oops, nothing found!"
});
$('#camp_list').css({
'width': '100%',
'height': '30px',
'border-radius': '2px'
});
$('#camp_list_chosen').css({
'width': '100%',
'height': '30px',
'border-radius': '2px'
});
$("#campaign_list_chosen").find("input").on('keyup', function () {
var final_list = '';
var srch_array = new Array();
var srch_option = new Array();
var list_option = new Array();
var str_srch = $(this).val();
var final_list_option = new Array();
srch_array = str_srch.split(" ");
var srch_array_lengh = srch_array.length;
$("#campaign_list option").each(function () {
list_option.push($(this).val());
});
for (var lo = 0; lo < list_option.length; lo++) {
var count_match = 0;
for (var sa = 0; sa < srch_array_lengh; sa++) {
if (list_option[lo].toLowerCase().indexOf(srch_array[sa]) >= 0) {
count_match++;
}
}
if (count_match == srch_array_lengh) {
final_list_option.push(list_option[lo]);
}
}
$("#campaign_list_chosen").find("ul").html('');
for (var fo = 0; fo < final_list_option.length; fo++) {
final_list = final_list + '<li class="active-result" style="" data-option-array-index="1">' + final_list_option[fo] + '</li>';
}
$(".chosen-results").html(final_list);
});
});

我在 jquery 下拉列表中添加了模糊逻辑..

但主要问题是,如果我在文本框中输入内容并从过滤列表中选择选项,则始终会选择第二个选项。

但是,如果我不输入任何内容并从 drpdown 中进行选择,则会选择相应的值。

例如,在文本框中输入“us Camp”,然后选择显示的选项。

您将看到仅选择了第二个选项。

如何解决..

最佳答案

我认为问题在于你在循环中分配的位置

for(var lo = 0; lo < list_option.length; lo++)

for(var sa = 0; sa <srch_array_lengh; sa++)

也许this是你想要的吗?

关于javascript - 所选下拉菜单的模糊逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29347467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com