html的form中动态添加action
2016-03-31 09:49
417 查看
第一种
第二种
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>
<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>
相关文章推荐
- HTML框架集示例
- html禁止手机页面放大缩小
- HTML初识
- HTML <input> accept 属性-规定能够通过文件上传进行提交的文件类型
- html 页面跳转 返回上一页 history 和 location
- 2016.3.21html标题,段落与格式化
- 笔记 - 9、HTML - XHTML
- 笔记 - 8、HTML - 表单
- 笔记 - 7、HTML - 内联(浮动)框架--iframe
- 笔记 - 6、HTML - 框架--frameset
- 笔记 - 5、HTML - 插入多媒体
- 笔记 - 3、HTML - 超链接
- 笔记 - 2、HTML - 表格
- 笔记 - 1、HTML - 列表
- html中的水平居中和垂直居中的问题。(固定高度与高度不定)
- html div 切割 上下左右 四个div
- 拆分字符串,GetHtmlByWebBrowser,UnicodeToMBCS,提升进程权限
- HTML学习(三)——表格
- HTML 全局属性
- html 标签详解(基础<html> <title>)