JavaScript window.location.href代码不工作

JavaScript window.location.href代码不工作,javascript,Javascript,我知道这个问题以前被问过很多次,但是没有一个修复方法对我有效。我做了一个窗口。位置。href以前做过的事情,但这一次没有。我知道该函数正在运行,因为我使用警报对其进行了测试。有人能看出这里有什么不对劲吗 <form> <input type="submit" name="agree" value="agree" onclick="fagree()"> <input type="submit" name="disagree" value="Decli

我知道这个问题以前被问过很多次,但是没有一个修复方法对我有效。我做了一个窗口。位置。href以前做过的事情,但这一次没有。我知道该函数正在运行,因为我使用警报对其进行了测试。有人能看出这里有什么不对劲吗

<form>

    <input type="submit" name="agree" value="agree" onclick="fagree()">
    <input type="submit" name="disagree" value="Decline and go to google" onclick="fdisagree()">

</form>

<script type="text/javascript">
function fagree(){
window.location.assign("index.html")
localStorage.setItem("Terms", "true")
}
function fdisagree(){
window.location.href="https://www.google.com/"
return false;
}
</script>
</body>

函数fagree(){
window.location.assign(“index.html”)
setItem(“术语”,“真”)
}
函数fdisagree(){
window.location.href=”https://www.google.com/"
返回false;
}

如果不需要,请不要将其放入表单中(如果示例中的表单代码是完整的)。在函数有机会触发之前提交它

或:


函数fagree(){
window.location.assign(“index.html”)
setItem(“术语”,“真”)
}
函数fdisagree(){
window.location.href=”https://www.google.com/"
返回false;
}

您可以使用
按钮
键入而不是提交,否则,表单将被提交

<form>
    <input type="button" name="agree" value="agree" onclick="fagree()">
    <input type="button" name="disagree" value="Decline and go to google" onclick="fdisagree()">
</form>

<script type="text/javascript">
function fagree(){
    window.location.assign("index.html");
    localStorage.setItem("Terms", "true"); //This line won't be executed, because the above line will reload the page
}

function fdisagree() {
    window.location.href="https://www.google.com/"
    return false; //This can be removed because the above line will redirect to google and the return false won't be executed
}
</script>

好的,thx,如果我明白了,把外部做成一个表单?哦,nvm,我把它做成了一个按钮
<form>
    <input type="button" name="agree" value="agree" onclick="fagree()">
    <input type="button" name="disagree" value="Decline and go to google" onclick="fdisagree()">
</form>

<script type="text/javascript">
function fagree(){
    window.location.assign("index.html");
    localStorage.setItem("Terms", "true"); //This line won't be executed, because the above line will reload the page
}

function fdisagree() {
    window.location.href="https://www.google.com/"
    return false; //This can be removed because the above line will redirect to google and the return false won't be executed
}
</script>
<button type="button" name="agree" value="agree" onclick="fagree()">
<button type="button" name="disagree" value="Decline and go to google" onclick="fdisagree()">