Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从URL中获取一个参数,添加+;1并插入到现有脚本中_Javascript - Fatal编程技术网

Javascript 从URL中获取一个参数,添加+;1并插入到现有脚本中

Javascript 从URL中获取一个参数,添加+;1并插入到现有脚本中,javascript,Javascript,我需要对两个现有脚本进行非常简单的更改,以便执行以下操作: 1) 从URL中获取步骤=的值(已完成,脚本#1) 2) 加上+1 3) 在脚本#2中插入值 示例URL 脚本#1 <html> <head> <script> function getURLParameter(name) { var query = window.location.search.substring(1); var vars = que

我需要对两个现有脚本进行非常简单的更改,以便执行以下操作:

1) 从URL中获取步骤=的值(已完成,脚本#1)

2) 加上+1

3) 在脚本#2中插入值

示例URL

脚本#1

<html>
<head>
<script>
    function getURLParameter(name) {  
        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] === name){return pair[1];}  
        }  
        return "";
    }
</script>
</head>

<body>
This is step nr. <script>document.write(getURLParameter('step'))</script>!
</body>
</html>

函数getURLParameter(名称){
var query=window.location.search.substring(1);
var vars=query.split(&);

对于脚本2中的(var i=0;i,可以调用脚本1中创建的函数


setTimeout(函数(){
bajb_backdetect.OnBack=函数(){
让step=parseInt(getURLParameter('step'))+1;
window.history.back=函数(){
文件.地点:https://www.mytracker.com/?step=“+步骤;
}
}
},200);

在脚本2中,可以调用脚本1中创建的函数


setTimeout(函数(){
bajb_backdetect.OnBack=函数(){
让step=parseInt(getURLParameter('step'))+1;
window.history.back=函数(){
文件.地点:https://www.mytracker.com/?step=“+步骤;
}
}
},200);

脚本2与脚本1在同一页吗?@MattEllen是!脚本2与脚本1在同一页吗?@MattEllen是!
<script type="text/javascript">
    setTimeout(function(){
        bajb_backdetect.OnBack = function(){
            window.history.back=function(){document.location='https://www.mytracker.com/?step='}
        }
    },200);
</script>