引用 | 編輯
henry014
2006-06-03 23:35 |
樓主
▼ |
||
x0
請問如何用JavaScript取得URL上得GET變數?就是網址上 ?name1=value1&name2=value2 要怎麼取得name1、name2的值? x0
|
引用 | 編輯
keigo
2006-06-04 00:12 |
1樓
▲ ▼ |
去拆字串...
先取得網頁的連結字串 然後就先拆出?以後的 再用=去切成陣列... 過幾天我再寫一篇教學好了...其實並不難. x0 |
引用 | 編輯
xxxx9659
2008-06-10 22:16 |
2樓
▲ ▼ |
下面是引用keigo於2006-06-04 00:12發表的 : 重點就是如何取得網頁上的URL阿!! 困難阿~~ x0 |
引用 | 編輯
xxxx9659
2008-06-10 23:09 |
3樓
▲ ▼ |
複製程式
<script> var url=window.location.toString(); var str=""; if(url.indexOf("?")!=-1){ //url裡有"?"符號 var ary=url.split("?")[1].split("&"); for(var i in ary){ str+=ary[i].split("=")[0]+":"; //變數名稱 str+=ary[i].split("=")[1]+"\n"; //變數值 } }else{ //url裡沒有"?"符號 str+="沒有get變數\n"; } window.alert(str); </script> 我錯了 用window.location就可以得到網址了 所以應該算簡單 x0 |
引用 | 編輯
sophia660125
2008-06-12 11:08 |
4樓
▲ |
大家都好厲害
x0 |