Javascript 尝试执行两个函数时js表单提交不起作用

Javascript 尝试执行两个函数时js表单提交不起作用,javascript,Javascript,我正在尝试从一个提交创建两个操作,但我的表单提交似乎不起作用。在function1()能够完成之前,function2()似乎已经接管了: double.php <DOCTYPE html> <html> <head></head> <body> <script> alert('here we go'); </script> </body> &

我正在尝试从一个提交创建两个操作,但我的表单提交似乎不起作用。在function1()能够完成之前,function2()似乎已经接管了:

double.php

<DOCTYPE html>
<html>
   <head></head>
   <body>
     <script>
       alert('here we go');
     </script>
   </body>   
<html>

警惕(“我们走了”);
double1.php

<DOCTYPE html>
<html>
   <head>
      <script>

       function function1(){ 
        document.getElementById("1").innerHTML = "1 changed!";     
        document.getElementById("theForm").action ='http://example.com/testbed/public/double.php';            
        document.getElementById('theForm').submit();        
       }
       function function2(){         
         document.getElementById("2").innerHTML = "2 changed!";
         window.location.replace("https://stackoverflow.com");
       }
      </script>
   </head>
   <body>
      <form method="post" action="" id="theForm">   
          <input type="button" onclick="function1();function2();" />
      </form>
      <div id='1'></div>
      <div id='2'><div>
   </body>
<html>

函数function1(){
document.getElementById(“1”).innerHTML=“1已更改!”;
document.getElementById(“theForm”).action='10〕http://example.com/testbed/public/double.php';            
document.getElementById('theForm').submit();
}
函数function2(){
document.getElementById(“2”).innerHTML=“2已更改!”;
window.location.replace(“https://stackoverflow.com");
}

您应该为什么事件使用AddEventListener?这两个函数做的事情相互矛盾——一个将表单提交到一个地址,另一个将窗口位置重定向到另一个地址。你期望这里会发生什么?@ConstantinGuidon这是一个编码风格的挑剔;这与问题无关。添加事件侦听器对我来说没有任何意义。我想执行一个我无法控制的php脚本,我想将url重定向到一个新页面,比如www.google.com或www.stackoverflow