html中关于form表单submit和button的提交用法详解

黄舟
Release: 2018-05-25 11:27:55
Original
21452 people have browsed it

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;
   }
}
Copy after login

在form表单里写成这样:

用户名
密 码

Copy after login

方法二:

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();
}
Copy after login

form表格的写法,需要写id

Copy after login

button按钮的写法如下:

Copy after login

The above is the detailed content of html中关于form表单submit和button的提交用法详解. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!