当前位置:编程学习 > JAVA >>

js的验证? 已经是完善的

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
  </head>
  
  <body>
   <form action="form" method="post" onsubmit="return check()">
    <table>
    <tr>
  <td> 
   <select id="sel" onChange="chg()" >
<option value="1" >1</option>
<option value="2">2</option>
<option value="3">3</option>
 </select>
</td>
    </tr>
    <tr>
     <td><input type="text"  id ="apid" name="apid" value="1"/></td>
     <td><input type="text"  id ="apid" name="apid" value="2"/></td>
     <td><input type="text"  id ="apid" name="apid" value="3"/></td>
    </tr>
   <tr> <td><input type="text" id ="masId" name="masId" /></td></tr>
   <tr>  <td><input type="text" id ="apIp" name="apIp" /></td></tr>
  <tr> <td><input type="text" name="apName" /></td></tr>
  <tr> <td><input type="submit" value="提交" /></td></tr>
     </table>
   </form>
  </body>
  <script type="text/javascript">
var mycars = new Array()
mycars[0] = "Saab"
mycars[1] = "Volvo"
mycars[2] = "BMW"
if(mycars.length == 3) {
var sel=document.getElementById('sel');
var option=sel.options[sel.selectedIndex = 0];
document.getElementsByName("apid")[0].value="46";
}
  
   if(document.getElementById("sel").value=="1"){
 document.getElementsByName("apid")[1].style.display="none";
 document.getElementsByName("apid")[2].style.display="none";
} else if (document.getElementById("sel").value=="2") {
 document.getElementsByName("apid")[2].style.display="none";
}


   function chg(){
if(document.getElementById("sel").value=="1"){
document.getElementsByName("apid")[0].style.display="";
 document.getElementsByName("apid")[1].style.display="none";
 document.getElementsByName("apid")[2].style.display="none";
}
if(document.getElementById("sel").value=="2"){
document.getElementsByName("apid")[0].style.display="";
document.getElementsByName("apid")[1].style.display="";
 document.getElementsByName("apid")[2].style.display="none";
}
if(document.getElementById("sel").value=="3"){
document.getElementsByName("apid")[0].style.display="";
document.getElementsByName("apid")[1].style.display="";
document.getElementsByName("apid")[2].style.display="";
}
  }
   function check() {
   alert("d");
   if(document.getElementsByName("apid")[0].value =="") {
   alert("apId不能为空");
   document.getElementsByName("apid")[0].focus();
   return false;
   }
  
   if(document.getElementById("masId").value == "") {
   alert("masId不能为空");
   document.getElementById("masId").focus();
   return false;
   }
   if(document.getElementById("masId").value.length >5) {
   alert("masId的长度不能大于5");
   document.getElementById("masId").focus();
   return false;
   } 
   if(isNaN(document.getElementById("apIp").value)) {
   alert("请输入数字");
   document.getElementById("apIp").focus();
   return false;
   }
   }
  </script>
</html>
--------------------编程问答-------------------- --------------------编程问答-------------------- 这点就算表单验证全了? 
空格限制,字节数限制,特殊字符限制。。。。 百分号 单引号  这些特殊字符  在你查数据库的时候是禁止的 还有你的长度限制 .length 也不行  --------------------编程问答--------------------
引用 2 楼  的回复:
这点就算表单验证全了? 
空格限制,字节数限制,特殊字符限制。。。。 百分号 单引号 这些特殊字符 在你查数据库的时候是禁止的 还有你的长度限制 .length 也不行
+1 --------------------编程问答--------------------  <form action="form" method="post" onsubmit="return check()">

用jquery就不用在表单里写事件了,我觉得表单写事件是对表单的污染。
补充:Java ,  J2ME
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,