【发布时间】:2015-04-29 23:07:58
【问题描述】:
我创建了一个查询字符串并将其附加到 URL,如下所示:
// HTML from index.html
<input type="button" value="Yes" onclick="redirect(this);" id="YES" class="btn btn-primary btn-lg">
<input type="button" value="No" onclick="redirect(this);" id="NO" class="btn btn-primary btn-lg">
// JS on index.html
function redirect(e){
var mapPg = "map.html";
var qString = "?choice=";
location.href = mapPg + qString + e.id;
}
从map.html 页面开始,我想获取该查询字符串并将其传递到除 index.html 页面之外的每个 URL。
当用户点击price.html pg 时,它将使用查询字符串调用一个函数,该函数将拉入数据以获得“是”的答案。 “否”的答案也是如此。
我不知道如何在点击时将查询字符串附加到每个 pg 的 URL。
导航是一个被拉入的 JavaScript 包含。我在导航中的所有<a> 中添加了一个qString 类,以防更容易定位它们。
【问题讨论】:
-
不能设置 cookie 或 sessionStorage 或 localStorage?
标签: javascript append query-string