当前位置: 首页 > 工具软件 > SubmitButton > 使用案例 >

form表单的两种提交方式,submit和button的用法

苍德寿
2023-12-01

form表单的两种提交方式,submit和button的用法

1.当输入用户名和密码为空的时候,需要判断。这时候就用到了校验用户名和密码,这个需要在jsp的前端页面写;有两种方法,一种是用submit提交。一种是用button提交。
方法一:

在jsp的前端页面的头部插入一个js方法:

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;
}
}

在form表单里写成这样:

<form id="formid" name= "myform" method = 'post' action = 'user_login_submit.action' onsubmit = "return checkUser();" >

用户名 <input type="text" value="" class="text2" name = "username" id = "userid"/>
密  码 <input type="password" value="" class="text2" name = "userpass" id = "userpassid"/>
 <div class="c4"> <input type="submit" value="" class="btn2" /> 方法二: 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();" />
 类似资料: