此代码适用于Mozilla Firefox,但不适用于Chrome。
<html>
<head>
<script language="Javascript">
<!--
function OnButton1()
{
document.Form1.action = "response1.php"
document.Form1.target = "_blank"; // Open in a new window
document.Form1.submit(); // Submit the page
return true;
}
function OnButton2()
{
document.Form1.action = "response2.php"
document.Form1.target = "_blank"; // Open in a new window
document.Form1.submit(); // Submit the page
return true;
}
-->
</script>
<noscript>You need Javascript enabled for this to work</noscript>
</head>
<body>
<form name="Form1" method="post">
Your Name <input type="text" name="name" size="10" /><br />
<INPUT type="button" value="Button1" name=name onclick="OnButton2();OnButton1();">
</form>
</body>
</html>
我们可以在onclick
处使用什么来触发这两项行动?
答案 0 :(得分:0)
感谢@dfsq提供答案!
如果你在第二次提交中添加很少的超时,那么在Chrome中实际上也是可能的
<html>
<head>
<script language="Javascript">
<!--
function OnButton1() {
document.Form1.action = "response1.php"
document.Form1.target = "_blank";
document.Form1.submit();
}
function OnButton2() {
document.Form1.action = "response2.php"
document.Form1.target = "_blank";
document.Form1.submit();
}
-->
</script>
</head>
<body>
<noscript>You need Javascript enabled for this to work</noscript>
<form name="Form1" method="post">
Your Name
<input type="text" name="name" size="10" />
<br />
<input type="button" value="Button1" name="name" onclick="OnButton1();setTimeout(OnButton2, 50)">
</form>
</body>
</html>
答案 1 :(得分:-3)
HTML按钮:
<input type="button" value="Button1" name="name" onclick="return OnButton1();">
JavaScript:
function OnButton1()
{
document.Form1.action = "response1.php"
document.Form1.target = "_blank"; // Open in a new window
document.Form1.submit(); // Submit the page
OnButton2(); //Calling second function here
}
function OnButton2()
{
document.Form1.action = "response2.php"
document.Form1.target = "_blank"; // Open in a new window
document.Form1.submit(); // Submit the page
return true;
}