一个简单的javascript类

原文链接: http://www.cnblogs.com/leonn/archive/2009/08/08/1541599.html

                     闲来无事,写个简单的js类,高手别看了~B("id名").Method  挺简单的,下面的方法名,已经给出方法的作用了,就不做解释了,直接拿去用吧!

ContractedBlock.gif ExpandedBlockStart.gif Code
function P(E)
{
    
var N = "";
    
this.Z = document.getElementById(E);
    
this.val = function(){ 
        
if(arguments.length==0)
        {
            
return this.Z.value;    
        }
        
else if(arguments.length=1)
        {
            
this.Z.value = arguments[0];
        }
    }
    
this.appendValAfter = function(){
        
this.Z.value = this.val() + arguments[0];
    }
    
this.appendValBefore = function(){
        
this.Z.value = arguments[0+ this.val();    
    }
    
this.html = function(){ 
        
if(arguments.length==0)
        {
            
return this.Z.innerHTML;    
        }
        
else if(arguments.length = 1)
        {
            
this.Z.innerHTML = arguments[0];
        }
    }
    
this.appendHtmlAfter = function(){
        
this.Z.innerHTML = this.html() + arguments[0];
    }
    
this.appendHtmlBefore = function(){
        
this.Z.innerHTML = arguments[0+ this.html();
    }
    
this.hide = function(){ this.Z.style.display = "none";}
    
this.show = function(){ this.Z.style.display = "inline-block";}
    
this.clearV = function(){ this.Z.value = N;}
    
this.clearH = function(){this.Z.innerHTML = N;}
    
this.toggle = function(){
       
var S = this.Z.style; S.display=="inline-block"?S.display="none":S.display="inline-block";
    }
    
//this.css = function(){ return this.Z.css}
}
//o.prototype.GV = 


function B(E){
    
return (new P(E));
}

转载于:https://www.cnblogs.com/leonn/archive/2009/08/08/1541599.html

猜你喜欢

转载自blog.csdn.net/weixin_30906185/article/details/94998947