【发布时间】:2015-04-30 21:09:08
【问题描述】:
在我的网络应用中,用户被问到一个问题,并且只能选择两个答案之一。是还是不是。根据他们的回答创建一个查询字符串。
以下代码通过每个页面的URL携带查询字符串:
var navlinks = document.getElementsByClassName("qString");
$(navlinks).prop("href", function() { return this.href + location.search; })
只有 2 个查询字符串,?choice=yes 和 ?choice=no。
一旦用户通过应用程序,如果他们从任何其他页面导航到park01.html、park02.html 或park03.html,数据将通过调用的function() 相应地提取。
这是我的伪代码概念:
// I assume I should store specific html pages to a variable
var parkPages = ["park01.html", "park02.html", "park03.html”];
if (user clicks on specified html pages stored in variable) {
and the url contains = ?choice=yes;
Then call these functions: funcA(), funcB(), funcC();
}
else {
the url contains = ?choice=no;
Then call these functions: funcD(), funcE(), funcF();
}
这个概念有意义吗?语法是什么样的?
【问题讨论】:
-
什么是
onClick parkPages?什么语法? -
我正在使用 JavaScript。而上面的概念是用JS伪代码写的。
-
用户是如何“通过应用”的?
-
你肯定想要
location.pathname,而不是location.search? -
我以前从未使用过查询字符串,所以这对我来说是新的。我想根据
index.html页面上生成的查询字符串调用特定函数。 @Bergi 用户使用全局导航栏在应用程序中导航。这就是我所说的“采取”的意思。
标签: javascript function logic query-string