使用 JavaScript 基于查询字符串调用函数

Call Functions Based On Query String Using JavaScript

在我的网络应用程序中,用户被问到一个问题并且只能从两个答案中选择一个。是还是不是。根据他们的回答创建查询字符串。

以下代码通过每个页面的 URL 携带查询字符串:

var navlinks = document.getElementsByClassName("qString");
    $(navlinks).prop("href", function() { return this.href + location.search; })

只有 2 个查询字符串,?choice=yes?choice=no

一旦用户浏览了该应用程序,如果他们从任何其他页面导航到 park01.htmlpark02.htmlpark03.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();
    }

这个概念有意义吗?语法是什么样的?

如果您只是想将伪代码具体翻译成 JavaScript,根据您最后的评论,这应该是您所需要的:

if (location.search === "?choice=yes") {
    funcA();
    funcB();
    funcC();
}
else {
    funcD();
    funcE();
    funcF();
}

虽然在这个阶段,我建议少花时间在这里,多花在基于 instructional/tutorial 的网站上。