jQuery拆分字符串 split()并且遍历$.each()

1.拆分字符串

语法:字符串名.split(separator,howmany)

separator 必需。字符串或正则表达式,从该参数指定的地方分割 stringObject。

howmany 可选。该参数可指定返回的数组的最大长度。如果设置了该参数,返回的子串不会多于这个参数指定的数组。如果没有设置该参数,整个字符串都会被分割,不考虑它的长度。

该方法会得到一个字符串数组

var chaoxiang = "${authElecEntrust.orientation}";
                var arr = chaoxiang.split('、');
                $.each(arr,function (index,obj) {
                    $("input:checkbox[name='chaoxiang'][value="+obj+"]").attr("checked", "true");
                })

2.遍历

$.each(数组名,function(index,obj){})

index通常为数组里面对象的索引,而obj为当前遍历到的对象

posted @ 2020-06-17 08:37  十月围城小童鞋  阅读(2223)  评论(0编辑  收藏  举报