您的位置:首页 > Web前端 > HTML

html的form中动态添加action

2016-03-31 09:49 417 查看
第一种

<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" onclick="addUser()" value="增加" />

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

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

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


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: