form表单的两种提交方式,submit和button的用法
来源:互联网 发布:铁血皇城辅助软件 编辑:程序博客网 时间:2024/05/20 16:42
1.当输入用户名和密码为空的时候,需要判断。这时候就用到了校验用户名和密码,这个需要在jsp的前端页面写;有两种方法,一种是用submit提交。一种是用button提交。
方法一:
var result = document.getElementById("userid").value;
var password = document.getElementById("userpassid").value;
if(result == "" ){
alert("用户名不能为空");
return false;
}
if(password == "" ){
alert("密码不能为空");
return false;
}else{
return true;
}
}
<form id="formid" name="myform" method='post'
action='user_login_submit.action' onsubmit="return checkUser();">
<table width="100%" border="0">
<tr>
<td width="60" height="40" align="right">用户名 </td>
<td><input type="text" value="" class="text2" name="username"
id="userid" /></td>
</tr>
<tr>
<td width="60" height="40" align="right">密 码 </td>
<td><input type="password" value="" class="text2"
name="userpass" id="userpassid" /></td>
</tr>
<tr>
<td width="60" height="40" align="right"> </td>
<td><div class="c4">
<input type="submit" value="" class="btn2" />
</div>
</td>
</tr>
</table>
</form>
</div>
方法二:
function checkUser(){
var result = document.getElementById("userid").value;
var password = document.getElementById("passid").value;
if(result == "" ){
alert("用户名不能为空");
return false;
}
if(password == "" ){
alert("密码不能为空");
return false;
}
document.getElementById("formid").submit();
}
form表格的写法,需要写id
<form id="formid" method = 'post' action = 'user_login_submit.action' >
button按钮的写法如下:
方法一:
在jsp的前端页面的头部插入一个js方法:
<jscript>
function checkUser(){var result = document.getElementById("userid").value;
var password = document.getElementById("userpassid").value;
if(result == "" ){
alert("用户名不能为空");
return false;
}
if(password == "" ){
alert("密码不能为空");
return false;
}else{
return true;
}
}
<jscript>
在form表单里写成这样:
<div><form id="formid" name="myform" method='post'
action='user_login_submit.action' onsubmit="return checkUser();">
<table width="100%" border="0">
<tr>
<td width="60" height="40" align="right">用户名 </td>
<td><input type="text" value="" class="text2" name="username"
id="userid" /></td>
</tr>
<tr>
<td width="60" height="40" align="right">密 码 </td>
<td><input type="password" value="" class="text2"
name="userpass" id="userpassid" /></td>
</tr>
<tr>
<td width="60" height="40" align="right"> </td>
<td><div class="c4">
<input type="submit" value="" class="btn2" />
</div>
</td>
</tr>
</table>
</form>
</div>
方法二:
function checkUser(){
var result = document.getElementById("userid").value;
var password = document.getElementById("passid").value;
if(result == "" ){
alert("用户名不能为空");
return false;
}
if(password == "" ){
alert("密码不能为空");
return false;
}
document.getElementById("formid").submit();
}
form表格的写法,需要写id
<form id="formid" method = 'post' action = 'user_login_submit.action' >
button按钮的写法如下:
<input type="button" value="" class="btn2" onclick = "checkUser();" />
当点击button时,会运行checkUser()的内容,从而进行前端验证非空
1 0
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- honey-----form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- 触发form表单的两种提交方式,submit和button的用法
- form表单的两种提交方式,submit和button的用法
- grpc源码注解(golang)
- leetcode53~Maximum Subarray
- Struts2 最新高危漏洞解决方案
- java的md5加密解密
- 你可记得曾经的-------- C#面向对象的“基础”
- form表单的两种提交方式,submit和button的用法
- 微软的 MSMQ (MessageQueue)的使用,一些理解,以及尝试
- Hibernate异常汇总
- Python学习笔记(三)--高级特性
- linux安装软件
- 有关使用sklearn LogisticRegression出现的 DeprecationWarning:
- Express、Nodejs服务器上传文件时出现Unexpected field
- Java 注解的应用
- java中关于final、fianlly、finalize三者的认识