본문 바로가기
Language(언어)/JavaScript

자바스크립트(JavaScript) javascript, setAttribute IE7, IE8~ 구분 적용

by 대학교닷컴 2013. 12. 10.


javascript, setAttribute IE7, IE8~ 구분 적용



Example #1 소개용 예제


var onclick = button_element.getAttribute("onclick");  


// if onclick is not a function, it's not IE7, so use setAttribute

if(typeof(onclick) != "function") { 

    button_element.setAttribute('onclick','doSomething();' + onclick); // for FF,IE8 ~ ,Chrome


// if onclick is a function, use the IE7 method and call onclick() in the anonymous function

} else {

    button_element.onclick = function() { 

        doSomething();

        onclick();

    }; // for IE7

}

 

하고자 하는 얘기는 IE7에서는 setAttribute method가 적용되지 않는 다는 점..

또 다른 얘를 들어보자면 (아래 예시 펌 사이트 :http://blog.naver.com/PostView.nhn?blogId=jwlee0208&logNo=10110476040 )

 


Example #2 소개용 예제


if($.browser.msie && $.browser.version < 8.0){

     input = document.createElement("<input type='text' name='articleName' style='width:95%;'>");

}else{

      input = document.createElement("input");

      input.setAttribute("type", "text");

      input.setAttribute(document.all ? "className" : "class","input01");

      input.setAttribute("style","width:95%;");

      input.setAttribute("id","articleName"+(articleLength+1));

      input.setAttribute("name","articleName");


}


[출처] javascript, setAttribute IE7, IE8~ 구분 적용|작성자 왕꼬부기


댓글