用JQERY怎么写网页1给网页2传值 网页2怎么接受到这个值
时间: 2024-03-11 20:47:57 浏览: 66
在jQuery中,可以使用`$.get()`方法来发送GET请求,将参数传递给网页2。在网页2中,可以使用JavaScript获取URL参数,与上面的回答类似。
以下是一个示例:
在网页1中,使用以下代码将参数传递给网页2:
```
$.get("page2.html", { value1: "xxx", value2: "yyy" });
```
其中,`page2.html`是网页2的URL,`value1`和`value2`是要传递的参数名,`xxx`和`yyy`是对应的参数值。
在网页2中,可以使用以下代码获取传递的参数:
```
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURIComponent(r[2]);
return null;
}
var value1 = getQueryString("value1");
var value2 = getQueryString("value2");
```
其中,`getQueryString()`函数是获取URL参数的函数,`name`是要获取的参数名,`value1`和`value2`就是传递的参数值。
阅读全文
相关推荐


















