获得get方法数组值 [英] get array value from get method

查看:517
本文介绍了获得get方法数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得在JavaScript数组的独立价值?

How to get separate values of array in javascript?

在一个页面:

变种C =新的Array(一); (如:α= {1,2})了window.location =my_details.html?+ C +_; 和在my_details.html:

var c=new Array(a); (eg: a={"1","2"}) window.location="my_details.html?"+ c + "_"; and in my_details.html :

my_details.htm:

my_details.htm:

var q=window.location.search;     
alert("qqqqqqqqqqqqq " + q);    
var arrayList = (q)? q.substring(1).split("_"):[];       
var list=new Array(arrayList);     
alert("dataaaaaaaaaaaa " +  decodeURIComponent(list)   + "llll " );  

但我不能够得到像列表[0]等:来自个人数组值
如何获得的呢?

But i am not able to get individual array value like list[0] etc
How to get it?

由于结果
Sneha

thanks
Sneha

推荐答案

德codeURIComponent()将返回一个字符串;你需要做的是这样的:

decodeURIComponent() will return you a String; you need to do something like:

var delim = ",",
    c = ["1", "2"];

window.location = "my_details.html?" + c.join(delim);

和再赚回来了一次:

var q = window.location.search,
    arrayList = (q)? q.substring(1).split("_"):[],       
    list = [arrayList];     
    arr = decodeURIComponent(list).split(delim);

这将使用 DELIM 的值作为分隔符,使阵列 A 字符串。然后,我们可以使用相同的分隔符的字符串分割回一个阵列。你只需要确保 DELIM 可在第二件code的范围内。

This will use the value of delim as the delimiter to make the Array a String. We can then use the same delimiter to split the String back into an Array. You just need to make sure delim is available in the scope of the second piece of code.

这篇关于获得get方法数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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