Posted on 2008-11-05 20:26
魚躍于淵 閱讀(227)
評論(0) 編輯 收藏 所屬分類:
javascript相關
網頁表單常用的check.js代碼
function LTrim(str){
var i;
for(i=0; i<str.length; i++){
if(str.charAt(i)!=" ") break;
str=str.substring(i,str.length) ;
return str;
}
}
function RTrim(str){
var i ;
for(i=str.length-1; i>=0; i++){
if(charAt(i)!=" ") break;
}
str = str.substring(0, i+1) ;
}
function Trim(str){
return LTrim(RTrim(str)) ;
}
function check(){
if(Trim(document.form1.title.value == "")){
alert("Sorry ! title is Empty !") ;
document.form1.title.focus() ;
return false ;
}
if(Trim(document.form1.cont.value == "")){
alert("Sorry ! cont is Empty !") ;
document.form1.cont.focus() ;
return false;
}
return true ;
|