Skip to content

Instantly share code, notes, and snippets.

@xsddz
Last active August 29, 2015 14:06
Show Gist options
  • Save xsddz/ada698d4835eda8b1029 to your computer and use it in GitHub Desktop.
Save xsddz/ada698d4835eda8b1029 to your computer and use it in GitHub Desktop.
在一个FORM表单中实现多个ACTION动作,三种方式
<p>原文地址:<a href="http://www.blogjava.net/hwaspf/articles/320491.html" target="_blank">在一个FORM中实现多个ACTION动作</a></p>
<form name="testForm" method="post" action="">
<input name="Name" type="text" id="Name">
<input type="button" name="Button" value="Act1" onClick="act1();">
<input type="button" name="Submit2" value="Act2" onClick="act2();">
</form>
<script language="JavaScript">
function act1()
{
document.testForm.action="a.jsp";
document.testForm.submit();
}
function act2()
{
document.testForm.action="b.jsp";
document.testForm.submit();
}
</script>
<form name="frm1" action="javascript:void(0)" method="post">
a.jsp <input type="radio" name="rad" checked><br>
b.jsp <input type="radio" name="rad"><br>
<input type="button" name="btn" value="Submit" onClick="sub(frm1,'_self')">
</form>
<script language=javascript>
function sub(form, target)
{
if (form.rad[0].checked) {
url = "/a.jsp";
form.action = url;
form.target = target;
form.submit();
} else if (form.rad[1].checked) {
url = "/b.jsp";
form.action = url;
form.target = target;
form.submit();
}
}
</script>
<hr>
<p>原文地址:<a href="http://spllot.iteye.com/blog/509075" target="_blank">一个表单,多个提交按钮,提交到不同的action</a></p>
<form name="myForm" action="javascript:void(0)" method="post">
<input type="button" value="提交" onclick="myForm.action='a.php';myForm.submit()">
<input type="button" value="预览" onclick="myForm.action='b.php';myForm.submit()">
<input type="button" value="更新" onclick="myForm.action='c.php';myForm.submit()">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment