将逗号分隔的输入框值拆分为jquery中的数组,并循环遍历 [英] Split comma-separated input box values into array in jquery, and loop through it

查看:43
本文介绍了将逗号分隔的输入框值拆分为jquery中的数组,并循环遍历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个隐藏的输入框,可使用以下方法从中检索逗号分隔的文本值(例如'apple,banana,jam')

I have a hidden input box from which I'm retrieving the comma-separated text value (e.g. 'apple,banana,jam') using:

var searchTerms = $("#searchKeywords").val();

我想将这些值分成一个数组,然后遍历该数组.

I want to split the values up into an array, and then loop through the array.

推荐答案

var array = $('#searchKeywords').val().split(",");

然后

$.each(array,function(i){
   alert(array[i]);
});

OR

for (i=0;i<array.length;i++){
     alert(array[i]);
}

这篇关于将逗号分隔的输入框值拆分为jquery中的数组,并循环遍历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆