gpt4 book ai didi

javascript - jquery组合框比较

转载 作者:行者123 更新时间:2023-11-28 02:38:39 24 4
gpt4 key购买 nike

我试图将数组中的值与 jquery 中组合框中的值进行比较,但没有成功。

我有一个这样的数组:(值1,值2,...)名称用分隔(例如:john smith,peter pan,)。另一方面,带有来自本地存储的值的组合框以这种方式动态附加

 $('select[name="selectListMenu1"]').append( new Option(nombre.fname + " " + nombre.lname) );

这给了我一个像“John smith”这样的最终名字,我将它附加到组合中。

现在我想将数组中的每个名称与组合框中的每个名称进行比较,并在组合框中选择匹配的名称。

var summary3 = (elnombre.proycontac).split(","); // split the names to compare
var p1 = summary3.length // get the number of names to compare
$('[name="selectListMenu1"] ').each(function(){ //from here i get lost
for (a=0; a<=p1-2; a++) {
if ($(this).text())=== summary3[a] {
// select the name in combobox
}
}
});

最佳答案

你可以试试这个:

$.map(summary3, function(elem, i) {
$('select[name="selectListMenu1"] option[text="' + elem + '"]').attr('selected', true);
});

我举了一个例子here .

关于javascript - jquery组合框比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13029705/

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