1、button 提交
<input type="button" name="" onclick="validate()" value="登录" >
js执行button传递的函数
<script type="text/javascript">
function validate() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
//alert(username.length);
var flag = true;
if(username == null || username == '' || username.length > 25 ){
alert("账号输入有误!");
flag = flase;
}
if( password == null || password == '' || password.length < 6){
alert("密码格式有误!");
flag = flase;
}
var actionForm = document.getElementById("actionForm");
if(flag){
actionForm.submit();
}
}
</script>
表单传递地址:
<form action="<%=request.getContextPath() %>/servlet/LoginServlet" name="actionForm" id="actionForm" method="post">
button 直接跳转目的地址:
<input type="button" onclick="javascript:window.location.href='<%=request.getContextPath()%>/register.jsp'" value="用户注册" />
2、submit
submit直接跳转目的地址:
<input type="submit" value="查询" />
表单填写的地址信息:
<form action="<%=request.getContextPath() %>/servlet/QueryServlet" method="post" >
submit跳转js进行本地验证:
表单填写方式:
<form action="login.do?act=login" method="post" onsubmit="return check(this)">
<input type=submit name="submit1" value="登陆">
<script type="text/javascript">
function check(form) {
if(form.userId.value=='') {
alert("请输入用户帐号!");
form.userId.focus();
return false;
}
if(form.password.value==''){
alert("请输入登录密码!");
form.password.focus();
return false;
}
return true;
}
</script>
3、超链接提交方式:
表单填写跳转地址:
<form action="<%=request.getContextPath() %>/servlet/QueryServlet" method="post" >
<a href="javaScript:page_nav1(document.forms[0],<%=pageNo-1%>)">上一页</a>
<a href="javaScript:page_nav1(document.forms[0],1)">1</a>
<a href="javaScript:page_nav1(document.forms[0],2)">2</a>
<a href="javaScript:page_nav1(document.forms[0],3)">3</a>
<a href="javaScript:page_nav1(document.forms[0],4)">4</a>
<a href="javaScript:page_nav1(document.forms[0],5)">5</a>
<a href="javaScript:page_nav1(document.forms[0],<%=pageNo+1%>)">下一页</a>
js代码参考:
function page_nav1(frm,pageNo){
//frm.setAttribute("pageNo",num);
frm.action="<%=request.getContextPath() %>/servlet/QueryServlet?pageNo="+pageNo;
frm.submit();
}
待补充。。。。。。。。