【发布时间】:2015-05-13 09:36:27
【问题描述】:
有什么方法可以过滤出数组中以字母 a 开头的项目。即
var fruit = 'apple, orange, apricot'.split(',');
fruit = $.grep(fruit, function(item, index) {
return item.indexOf('^a');
});
alert(fruit);
【问题讨论】:
-
在 jQuery 中试试这个:
var $beginswitha = $(":input[name^='a']")。然后将该变量放在您的 indexOf 语句中。
标签: javascript jquery arrays indexof