道非道 非常道

          勤思、謹言、慎行、厚積、薄發

          導航

          <2009年7月>
          2829301234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          公告

          在非洲,
          瞪羚每天早上醒來時,
          他知道自己必須跑的比最快的獅子還快,
          否則就會被吃掉。
          獅子每天早上醒來時,
          他知道自己必須追上跑的最慢的瞪羚,
          否則就會被餓死。
          不管你是獅子還是瞪羚,
          當太陽升起時,你最好開始奔跑。

          ----摘自<世界是平的>-托馬斯.弗里德曼



          隨筆分類(92)

          文章分類(58)

          收藏夾(11)

          隨筆檔案(106)

          文章檔案(66)

          統計

          web

          天圓

          經濟 政治 軍事

          鍵康

          [轉] 關于 insertAdjacentHTML insertAdjacentText

           

           1添加html內容(insertAdjacentHTML和insertAdjacentText)
           2    dhtml提供了兩個方法來進行添加,insertAdjacentHTML和insertAdjacentText
           3insertAdjacentHTML方法:在指定的地方插入html標簽語句。
           4    原型:insertAdjacentHTML(swhere,stext)
           5    參數:
           6    swhere:指定插入html標簽語句的地方,有四種值可以用:
           7              1.beforeBegin:插入到標簽開始前
           8              2.afterBegin:插入到標簽開始標記后
           9              3.beforeEnd:插入到標簽結束標記前
          10              4.afterEnd:插入到標簽結束標記后
          11              stext:要插入的內容
          12      例:var sHTML="<input type=button onclick=" +     "go2()" + " value='Click Me'><BR>"
          13      var sScript='<SCRIPT DEFER>'
          14      sScript = sScript +     'function go2(){ alert("Hello from inserted script.") }'
          15      sScript = sScript + '
          </script' + '>';
          16      ScriptDiv.insertAdjacentHTML("afterBegin",sHTML + sScript);
          17      在html正文中加入一行:
          18    <DIV ID="ScriptDiv"></Div>
          19     最終變成:
          20    <DIV ID="ScriptDiv">
          21       <input type=button onclick=go2() value='Click Me'><BR>
          22       <SCRIPT DEFER>
          23         function go2(){alert("Hello from inserted sctipt.")}'
          24       
          </script>
          25     </DIV> 
          26     insertAdjacentText方法與insertAdjacentHTML方法類似,只不過只能插入純文本,參數相同
          27trackback:http://gmfzh.bokee.com/3680267.html 
          28
          29
          30方法名稱:insertHtml(where,el,html)
          31
          32參數介紹:
          33where:插入位置。包括beforeBegin,beforeEnd,afterBegin,afterEnd。
          34el:用于參照插入位置的html元素對象
          35html:要插入的html代碼
          36
          37源碼如下:
          38<script type="text/javascript">
          39  <!--
          40    function insertHtml(where, el, html){
          41        where = where.toLowerCase();
          42        if(el.insertAdjacentHTML){
          43            switch(where){
          44                case "beforebegin":
          45                    el.insertAdjacentHTML('BeforeBegin', html);
          46                    return el.previousSibling;
          47                case "afterbegin":
          48                    el.insertAdjacentHTML('AfterBegin', html);
          49                    return el.firstChild;
          50                case "beforeend":
          51                    el.insertAdjacentHTML('BeforeEnd', html);
          52                    return el.lastChild;
          53                case "afterend":
          54                    el.insertAdjacentHTML('AfterEnd', html);
          55                    return el.nextSibling;
          56            }

          57            throw 'Illegal insertion point -> "' + where + '"';
          58        }

          59  var range = el.ownerDocument.createRange();
          60        var frag;
          61        switch(where){
          62             case "beforebegin":
          63                range.setStartBefore(el);
          64                frag = range.createContextualFragment(html);
          65                el.parentNode.insertBefore(frag, el);
          66                return el.previousSibling;
          67             case "afterbegin":
          68                if(el.firstChild){
          69                    range.setStartBefore(el.firstChild);
          70                    frag = range.createContextualFragment(html);
          71                    el.insertBefore(frag, el.firstChild);
          72                    return el.firstChild;
          73                }
          else{
          74                    el.innerHTML = html;
          75                    return el.firstChild;
          76                }

          77            case "beforeend":
          78                if(el.lastChild){
          79                    range.setStartAfter(el.lastChild);
          80                    frag = range.createContextualFragment(html);
          81                    el.appendChild(frag);
          82                    return el.lastChild;
          83                }
          else{
          84                    el.innerHTML = html;
          85                    return el.lastChild;
          86                }

          87            case "afterend":
          88                range.setStartAfter(el);
          89                frag = range.createContextualFragment(html);
          90                el.parentNode.insertBefore(frag, el.nextSibling);
          91                return el.nextSibling;
          92            }

          93            throw 'Illegal insertion point -> "' + where + '"';
          94    }

          95    
          96  trackback: http://www.aygfsteel.com/Scott/archive/2007/08/30/141449.html
          97

          posted on 2009-07-09 10:37 星期五 閱讀(374) 評論(0)  編輯  收藏 所屬分類: web 開發

          主站蜘蛛池模板: 江城| 雅江县| 清涧县| 龙泉市| 保康县| 合肥市| 镇平县| 太和县| 安岳县| 阿鲁科尔沁旗| 营口市| 平舆县| 保靖县| 承德县| 车险| 昌图县| 汽车| 山阴县| 赤城县| 浮山县| 沭阳县| 余干县| 神池县| 佛学| 普宁市| 胶州市| 同仁县| 遂溪县| 峨山| 江山市| 新竹县| 辰溪县| 宁城县| 南阳市| 屏山县| 杭锦后旗| 清流县| 民县| 吉林省| 巴东县| 班玛县|