【发布时间】:2010-09-18 21:38:24
【问题描述】:
我想知道是否有人可以建议使用 jQuery 循环遍历 <select> 元素中的所有 <option> 并构建数组的最佳方法。
例如。
而不是下面的,将字符串 ins 传递给 autoCompleteArray(),
$("#CityLocal").autocompleteArray(
[
"Aberdeen", "Ada", "Adamsville", "Zoar" //and a million other cities...
],
{
delay:10,
minChars:1,
matchSubset:1,
onItemSelect:selectItem,
onFindValue:findValue,
autoFill:true,
maxItemsToShow:10
}
);
...我需要遍历<select> 中的所有<options> 并将它们推送到一个数组中,然后将该数组变量传递给函数而不是一个长字符串。
例如,
$("#CityLocal").autocompleteArray(
[
MyBigArrayOfOptions
],
{
delay:10,
minChars:1,
matchSubset:1,
onItemSelect:selectItem,
onFindValue:findValue,
autoFill:true,
maxItemsToShow:10
}
);
如果您能建议如何以正确的格式将内容推送到数组中,我将不胜感激。我已经从本网站的另一篇文章中猜到了循环部分。
谢谢。
【问题讨论】:
标签: javascript jquery autocomplete