孤灯野火
畅想的天空
posts - 2,comments - 4,trackbacks - 0
  • <%@page contentType="text/html;charset=gb2312"%>   
  • <html>   
  • <head>   
  • <!-- 判断输入的是否为空,空的话就返回该焦点的javascript代码 -->   
  • <script language="javasctipt" type="text/javascript">   
  •   function login(){   
  •    //thisForm是form中的name   
  •     var form = document.thisForm;   
  •        
  •     if(trim(form.name.value) == ""){   
  •         window.alert("请输入姓名!");   
  •         form.name.select();//或者form.name.focus()   
  •         return;   
  •     }   
  • /**或像下面那样也可以  
  • if (trim(document.thisForm.username.value)=="")  
  •     {  
  •         alert("请填写您的姓名!");  
  •         document.thisForm.name.focus();  
  •         return ;//false;  
  •     }  
  • */  
  •     if(trim(form.password.value) == ""){   
  •         window.alert("请输入密码!");   
  •         form.password.select();   
  •         return;   
  •     }   
  •   
  •       // 还可以做很多事情,比如在这里又调用其他的function来触发其他事件   
  •        
  •     form.target = "_blank";//弹出新的页面   
  •     form.action = "isNull.jsp";//form中的action值   
  •     form.method = "post";   
  •     form.submit();//提交form         
  •   }   
  •   /** 修剪字串前后的空格  */  
  • function trim(s) {   
  •   var count = s.length;   
  •   var st    = 0;       // start   
  •   var end   = count-1// end   
  •   
  •   if (s == ""return s;   
  •   while (st < count) {   
  •     if (s.charAt(st) == " ")   
  •       st ++;   
  •     else  
  •       break;   
  •   }   
  •   while (end > st) {   
  •     if (s.charAt(end) == " ")   
  •       end --;   
  •     else  
  •       break;   
  •   }   
  •   return s.substring(st,end + 1);   
  • }   
  • </script>   
  • posted on 2009-09-04 12:15 孤飞燕 阅读(1450) 评论(0)  编辑  收藏 所属分类: JS

    只有注册用户登录后才能发表评论。


    网站导航: