【问题标题】:How do I pass multiple variables through a URL in Javascript如何通过 Javascript 中的 URL 传递多个变量
【发布时间】:2018-10-22 07:55:48
【问题描述】:

伙计们,

这里的第一个问题并尝试自学 js 和 jquery,请原谅(或更正)命名法中的任何错误......

我很高兴使用这段代码将变量从一个页面传递到另一个页面:

function openPage() {window.open('datapage_test.html?id=' + dataset[0].Var_Name)}

返回:file:///*path*/datapage_test.html?id=UK_Wakefield

当我尝试扩展它以传递多个变量时,我失败了:

function openPage() {
    window.open('datapage_test.html?id=' + dataset[0].Var_Name + dataset[0].Var_Class + dataset[0].Var_Instance )
}

返回: file:///C:/*path*/datapage_test.html?id=WakefieldundefinedUK

感谢所有的指点。 J

【问题讨论】:

  • 看来dataset[0].Var_Class 是undefined。确保您正确拼写了住宿名称 (Var_Class)。

标签: javascript url


【解决方案1】:

网址是这样配置的:

http://www.example.com/images/assets/file.html?id=1&type=2
protocol://domainName.com/path/to/myFile.html?parameter=value&other=value

这是您尝试做的重要部分?parameter=value&other=value

你可以试试这样的:

  function openPage() {window.open('datapage_test.html?id=' + dataset[0].Var_Name +'&val2=' + dataset[0].Var_Class +'&val3=' + dataset[0].Var_Instance )}

希望这会有所帮助:)

【讨论】:

    【解决方案2】:

    urls 中的起始变量是使用? 完成的,这就是你正在做的,但是,对于之后的变量,你使用&。例如,如果我有变量 cat = meow 和 dog = woof,您可以使用 http://example.com/?cat=meow&dog=woof。

    另外,可能需要检查dataset[0].Var_Class。显然它在你的例子中是未定义的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-03
      • 2016-09-30
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 2011-10-19
      • 2017-04-03
      相关资源
      最近更新 更多