html的form中动态添加action

第一种


<script type="text/javascript"> 
$(function(){ 
var thisForm = document.forms['form1']; //获取name为form1的form表单 
//或者 
//var thisForm = document.forms[0]; //获取第一个form表单 
console.info(thisForm.username.value); //输出表单name属性值为form1的 username的值 
console.info(thisForm.address.value); 
document.forms[0].submit(); //表单提交 
}) 
</script>
<body> 
<!-- 以下为三个简单的form表单 -->
<form action="x" name="form1" > 
<input type="text" name="username" value="zhangsan" /> 
<input type="text" name="address" value="beijing" /> 
</form> 
 
<form action="x" name="form2" > 
</form> 
 
<form action="x" name="form3" > 
</form> 
</body>




第二种

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>

<script type="text/javascript">
	//var myfrom=document.getElementById("myform1");

	
	function addUser()
	{
		var myform=document.forms[0];
		myform.action="user/addUser_success";
		myform.method="post";
		myform.submit();
	}
	<pre id="best-content-1048411421" accuse="aContent" class="best-text mb-10" style="margin-top: 0px; margin-bottom: 10px; padding: 0px; font-family: arial, 'courier new', courier, 宋体, monospace, 'Microsoft YaHei'; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; color: rgb(51, 51, 51); line-height: 24px; background-color: rgb(243, 255, 236);"><span style="white-space:pre">		</span>//forms[0] 是你网页中的第一个表单,form的action属性是发送请求去的文件,就是处理你表单请求的动态网页。
<span style="white-space:pre">		</span>//例如:document.form[0].action="1.asp" 就是你的表单提交时,处理你请求的网页时1.asp

function modifyUser(){var myform=document.forms[0];myform.action="user/modifyUser_success";myform.method="post";myform.submit();}function deleteUser(){var myform=document.forms[0];myform.action="user/deleteUser_success";myform.method="post";myform.submit();}</script></head><body>

<form id="myform1" >用户名:<input type="text" name="user.name" />

<br />密码:<input type="text" name="user.password" />

<br />年龄:<input type="text" name="user.age" /><br />

<input type="button" name="btnadd" οnclick="addUser()" value="增加" />

<input type="button" name="btnmodify" οnclick="modifyUser()" value="修改" />

<input type="button" name="btndel" οnclick="deleteUser()" value="删除" /> 

</form></body></html>

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值