addClass,removeClass

function addClass(obj,aclass){
    if(obj.className == ''){
        obj.className = aclass;
    }else{
        var arr = obj.className.split(' ');
        var _index = arrIndexOf(arr,aclass);
        if(_index == -1){
            obj.className += ' '+aclass;
        }
    }   
}
function removeClass(obj,aclass){
    if(obj.className!=''){
        var arr = obj.className.split(' '); 
        var _index = arrIndexOf(arr,aclass);
        if(_index != -1){
            arr.splice(_index,1);
            obj.className = arr.join(' ');
        }
    }
}
function arrIndexOf(arr,v){
    for(var i=0;i<arr.length;i++){
        if(arr[i] == v){
            return i;
        }
    }
    return -1;
};

 

posted @ 2014-09-13 13:06  潇潇杀  阅读(227)  评论(0编辑  收藏  举报