接收Javascript参数不起作用

问题描述 投票:-1回答:1

var num = getQueryVariable("param1");

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i = 0; i < vars.length; i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
  alert('Query Variable ' + variable + ' not found');
}

function mynewFunction {
  var numnew = num + 1;
  window.location = "?image=" + numnew;
}

function myFunction() {
  var numnew = num - 1;
  window.location = "?image=" + numnew;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<button onclick="mynewFunction()" id="forward"><i class="fa fa-backward"></i>
</button>
<button onclick="mysecondnewFunction()"></button>
<button onclick="myFunction()"><i class="fa fa-forward"></i>
</button>

[当我按下前进按钮时,当URL为/gallerySingle.htm?image=1时,我希望上面的代码将参数“ image”更改为2,但是它没有任何改变。

javascript dom
1个回答
1
投票

我注意到的第一件事是mynewFunction定义不正确,您缺少了()

function mynewFunction() {
  var numnew = num + 1;
  window.location = "?image=" + numnew;
}
© www.soinside.com 2019 - 2024. All rights reserved.