我正在尝试将数组中的值与 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
}
}
});