动态改变表单action的值

有时根据实际需要会设置不同的按钮,当点击不同的按钮时将同一表单发送到不同的页面中进行处理,这就需要动态的改变表单action的值,实现方法如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function fun1(){
    document.form1.action="asp1.asp";
    document.form1.submit();
    return true;
}
function fun2(){
    document.form1.action="asp2.asp";
    document.form1.submit();
    return true;
}
</script>
<body>
<form id="form1" name="form1" method="post" action="">
  <input type="button" name="Submit" onclick="fun1();" value="收藏" />
  <input type="button" name="Submit2" onclick="fun2();" value="提交" />
</form>
</body>
</html>


评论: 1 | 引用: 0 | 查看次数: 4844
发表评论
登录后再发表评论!