如何使用GET向Javascript发送数据

时间:2010-01-04 07:28:28

标签: javascript get

我不知道如何使用GET将数据发送到Java Script 喜欢从

link:C:/folder/test.html?x = 1

<script>
//when page accessed
//access x data sent in from the link
</script>

注意,这是针对客户端页面而不是服务器!

2 个答案:

答案 0 :(得分:1)

this您要找的是什么?

答案 1 :(得分:0)

您需要解析location.search。一个简单的实现是:

var matches = null;
var params = {}, raw_params = location.search.substring(1).split('&');
for (i in raw_params)
{
    matches = raw_params[i].match (/^([^=]+)=(.+)$/);
    if (matches) params[matches[1]] = matches[2];
}