부분 함수

4593 단어
function addLoadEvent(func){
    var oldonload=window.onload;
    if(typeof window.onload !='function'){
        window.onload=func;
    }else{
        window.onload=function(){
            oldonload();
            func();
        }
    }
}// , addLoadEvent( ) 

페이지 로드 완료 시 실행 함수
 
function insertAfter(newElement,targetElement){//
    var parent=targetElement.parentNode;// parentNode parent 
    if(parent.lastChild==targetElement){// parent  
        parent.appendChild(newElement);// parent 
    }else{
        parent.insertBefore(newElement,targetElement.nextSibling);// 
    }
}

insertAfter 함수
 
function addClass(element,value){
    if(!element.className){
        element.className=value;
    }else{
        newClassName=element.className;
        newClassName+=" ";
        newClassName+=value;
        element.className=newClassName;
    }
}// className 

className 속성에 값 지정
 
function focusLabels(){
    if(!document.getElementsByTagName)return false;
    var labels=document.getElementsByTagName("label");
    for(var i=0;i<labels.length;i++){
        if(!labels[i].getAttribute("for"))continue;
        labels[i].onclick=function(){
            var id=this.Attribute("for");
            if(!document.getElementById(id))return false;
            var element=document.getElementById(id);
            element.focus();
        }
    }
}
addLoadEvent(focusLabels);// label 

단일 레이블은 해당 폼에 초점을 맞춘다
 
function resetFields(whichform){
    if(!Modernizr.input.placeholder)return;
    for (var i=0;i<whichform.elements.length;i++){
        var element=whichform.elements[i];
        if(!element.type=="submit")continue;
        var check=element.placeholder||element.getAttribute('placeholder');
        if(!check)continue;
        element.onfocus=function(){
            var text=this.placeholder||this.getAttribute('placeholder');
            if(this.value==text){
                this.className='';
                this.value='';
            }
        }
        element.onblur=function(){
            if(this.value==""){
                this.className='placeholder';
                this.value=this.placeholder||this.getAttribute('placeholder');
            }
        }
        element.onblur();
    }
}
function prepareForms(){
    for(var i=0;i<document.forms.length;i++){
        var thisform=document.forms[i];
        resetFields(thisform);
    }
}
addLoadEvent(prepareForms);// 

양식 자리 표시자

좋은 웹페이지 즐겨찾기