可惡的 IE innerHTML @ 工作小錦囊 :: 隨意窩 Xuite日誌
  • 關鍵字
    linuxOpenSUSErpmDesktopqmailnagioszyppersshphpwindowstrac打包uploadrnmsputtyvncmonitoringsocatperlhtmlproxymysqlsocksnagvisterminalvpopmailrrdtoolmrtgciscopamapache2snmpnetworkmtadbdovecotdnspop3imapipapacheshellpicasapdfpatchvimfirefoxmp3qtopensusemore
  • 常用連結
    1. 沒有新回應!






  • 如何使用RSS
    Powered by Xuite
    2006-12-03 15:03 可惡的 IE innerHTML
    平均分數:0 顆星    投票人數:0
    我要評分:

    你知道嗎? IE 的 innerHTML 不能插入 script code ?

    http://www.jsmadeeasy.com/javascripts/Advanced/innerHtml/innerHtml.htm

    When using innerHTML to insert script, you must include the DEFER attribute in the script element.

    http://big5.chinaz.com:88/blog.chinaz.com/u1/wilson/archives/2006/37879.shtml

    不能插入 <script></script> 就算了, 竟然連 <a href=# onclick='my_script()'> 這種都不行.

    在 FF 只要

     var ie = (document.all)? true: false;
     var obj = document.getElementById("recent");
     obj.innerHTML="";

    if (!ie) {
    for (i=keep_recent.length -1; i >=0  ; i-- ) {
       text ="<a href='javascript:gototo(\""+ keep_recent[i] + "\")>" + keep_recent[i] +"</a>&nbsp;";
       obj.innerHTML+=text;
      if ( i%3 == 0) {
        obj.innerHTML+="<br>";
      }
     }
     return;
    }

    但是 IE 只能用 innerHTML塞入正常的 span tag, 然後再賦予其 onClick 等 function..

    if (ie) {
    /*

    // 想先產生另一個 object 再複製過去也不行
       var bugIE = document.createElement('span');
       obj.appendChild(bugIE);
       bugIE.innerHTML="<a href='javascript:gototo(\""+ keep_recent[i] + "\")>" + keep_recent[i] +"</a>&nbsp;";

       // alert(bugIE.innerHTML);
      

    not work. http://www.jsmadeeasy.com/javascripts/Advanced/innerHtml/innerHtml.htm
    .
    */
    // Changes the cursor to an hourglass
    function cursor_hand() {
    document.body.style.cursor = 'hand';
    }

    // Returns the cursor to the default pointer
    function cursor_clear() {
    document.body.style.cursor = 'default';
    }

    var bugIE;
    for (i=keep_recent.length -1; i >=0  ; i-- ) {
       text ="<span id=span"+i+" style='text-decoration: underline;color: blue'>" + keep_recent[i] +"</span>&nbsp;";
       obj.innerHTML+=text;
      if ( i%3 == 0) {
        obj.innerHTML+="<br>";
      } }}
    }
    for(i=0; i< keep_recent.length; i++ ){
       var bugIE = document.getElementById('span'+i);
        bugIE.onclick=function () {
         gototo(this.innerHTML); };
        bugIE.onmouseover=cursor_hand;
        bugIE.onmouseout=cursor_clear;
     }

    }

    蚯蚓 / Xuite日誌 / 回應(1) / 引用(0) / 好文轉寄
    回應