从get方法获取数组值

时间:2011-12-19 09:07:52

标签: javascript android get

如何在javascript中获取单独的数组值?

在一页中:

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

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 " );  

但是我无法像list [0]等获得单个数组值 怎么弄?

感谢
斯纳

1 个答案:

答案 0 :(得分:0)

decodeURIComponent()会给你一个String;你需要做类似的事情:

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的值作为分隔符,使Array成为String。然后,我们可以使用相同的分隔符将String拆分为Array。您只需要确保delim在第二段代码的范围内可用。