textutil

var  TextUtil  =   new  Object;

TextUtil.isNotMax 
=   function (oTextArea) {
    
return  oTextArea.value.length  !=  oTextArea.getAttribute( " maxlength " );
};

TextUtil.blockChars 
=   function  (oTextbox, oEvent, bBlockPaste) {

    oEvent 
=  EventUtil.formatEvent(oEvent);
         
    
var  sInvalidChars  =  oTextbox.getAttribute( " invalidchars " );
    
var  sChar  =  String.fromCharCode(oEvent.charCode);
    
    
var  bIsValidChar  =  sInvalidChars.indexOf(sChar)  ==   - 1 ;
       
    
if  (bBlockPaste) {
        
return  bIsValidChar  &&   ! (oEvent.ctrlKey  &&  sChar  ==   " v " );
    } 
else  {
        
return  bIsValidChar  ||  oEvent.ctrlKey;
    }
};

TextUtil.allowChars 
=   function  (oTextbox, oEvent, bBlockPaste) {

    oEvent 
=  EventUtil.formatEvent(oEvent);
         
    
var  sValidChars  =  oTextbox.getAttribute( " validchars " );
    
var  sChar  =  String.fromCharCode(oEvent.charCode);
    
    
var  bIsValidChar  =  sValidChars.indexOf(sChar)  >   - 1 ;
    
    
if  (bBlockPaste) {
        
return  bIsValidChar  &&   ! (oEvent.ctrlKey  &&  sChar  ==   " v " );
    } 
else  {
        
return  bIsValidChar  ||  oEvent.ctrlKey;
    }
};

TextUtil.blurBlock 
=   function (oTextbox) {

    
// get the invalid characters
     var  sInvalidChars  =  oTextbox.getAttribute( " invalidchars " );

    
// split the invalid characters into a character array
     var  arrInvalidChars  =  sInvalidChars.split( "" );
    
    
// iterate through the characters
     for  ( var  i = 0 ; i <  arrInvalidChars.length; i ++ ){
        
if  (oTextbox.value.indexOf(arrInvalidChars[i])  >   - 1 ) {
            alert(
" Character ' "   +  arrInvalidChars[i]  +   " ' not allowed. " );
            oTextbox.focus();
            oTextbox.select();
            
return ;
        }
    }    
};


TextUtil.blurAllow 
=   function (oTextbox) {
    
// get the valid characters
     var  sValidChars  =  oTextbox.getAttribute( " validchars " );
    
    
// split the textbox value string into a character array
     var  arrTextChars  =  oTextbox.value.split( "" );
   
    
// iterate through the characters
     for  ( var  i = 0 ; i <  arrTextChars.length; i ++ ){
        
if  (sValidChars.indexOf(arrTextChars[i])  ==   - 1 ) {
             alert(
" Character ' "   +  arrTextChars[i]  +   " ' not allowed. " );
             oTextbox.focus();
             oTextbox.select();
             
return ;
        }
    }
};    

TextUtil.numericScroll 
=   function  (oTextbox, oEvent) {

    oEvent 
=  EventUtil.formatEvent(oEvent);
    
var  iValue  =  oTextbox.value.length  ==   0   ?   0  :parseInt(oTextbox.value);
    
    
var  iMax  =  oTextbox.getAttribute( " max " );
    
var  iMin  =  oTextbox.getAttribute( " min " );

    
if  (oEvent.keyCode  ==   38 ) {
        
if  (iMax  ==   null   ||  iValue  <  iMax) {
            oTextbox.value 
=  (iValue  +   1 );
        }
    } 
else   if  (oEvent.keyCode  ==   40 ){
        
if  (iMin  ==   null   ||  iValue  >  iMin) {
            oTextbox.value 
=  (iValue  -   1 );
        }
    }
};

TextUtil.autosuggestMatch 
=   function  (sText, arrValues) {

    
var  arrResult  =   new  Array;

    
if  (sText  !=   "" ) {
        
for  ( var  i = 0 ; i  <  arrValues.length; i ++ ) {
            
if  (arrValues[i].indexOf(sText)  ==   0 ) {
                arrResult.push(arrValues[i]);
            }
        }
    }

   
return  arrResult;

};

TextUtil.autosuggest 
=   function  (oTextbox, arrValues, sListboxId) {
    
    
var  oListbox  =  document.getElementById(sListboxId);
    
var  arrMatches  =  TextUtil.autosuggestMatch(oTextbox.value, arrValues);
    
    ListUtil.clear(oListbox);
    
    
for  ( var  i = 0 ; i  <  arrMatches.length; i ++ ) {
        ListUtil.add(oListbox, arrMatches[i]);
    }
    
};

转载于:https://www.cnblogs.com/jackhuclan/archive/2008/04/12/1150103.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值