zoukankan      html  css  js  c++  java
  • innerHTML,createElement

     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>豪情</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    </head>
    <body>
        <input type="button" value="test-01" onclick="test1()" /><input type="text" name="" readonly="readonly" id="t1" /><br />
        <input type="button" value="test-02" onclick="test2()" /><input type="text" name="" readonly="readonly" id="t2" /><br />
        <input type="button" value="清空" onclick="clearVal()" />
        <div id="div1">this is div1</div>
        <div id="div2">this is div2</div>
        <script type="text/javascript">
            var d = new Date().getTime(), buf = [],
                div1 = document.getElementById('div1'),
                div2 = document.getElementById('div2'),
                t1 = document.getElementById('t1'),
                t2 = document.getElementById('t2');
            function test1(){
                for(var i=0; i<1000; i++){
                    buf.push('<div><a href="#">测试');
                    buf.push(i);
                    buf.push('</a></div>');
                }
                div1.innerHTML = buf.join('');
                t1.value = '耗时:' + (new Date().getTime() - d) + ' 毫秒';
            }
            function test2(){
                for(var i=0; i<1000; i++){
                    var a = document.createElement('a');
                    var div = document.createElement('div');
                    a.href = '#';
                    a.innerHTML = '测试';
                    div.appendChild(a);
                    div2.appendChild(div);
                }
                t2.value = '耗时:' + (new Date().getTime() - d) + ' 毫秒';
            }
            function clearVal(){
                div1.innerHTML = '';
                div2.innerHTML = '';
                t1.value = '';
                t2.value = '';
            }
        </script>
    </body>
    </html>

  • 相关阅读:
    BZOJ 1066 [SCOI2007]蜥蜴 (最大流)
    Codeforces 1092 D2 Great Vova Wall (Version 2) (栈)
    BZOJ 1046 [HAOI2007]上升序列(LIS + 贪心)
    牛客练习赛34 D little w and Exchange(归纳)
    BZOJ 1042 [HAOI2008]硬币购物(完全背包+容斥)
    GTMD并查集!
    2018icpc南京现场赛-G Pyramid(打标找规律+逆元)
    drwxr-xr-x 2 root root 4096 06-29 14:30 Test 分段解释
    Linux里面非常重要的目录
    点击 触发 事件 的 jQuery 写法样式
  • 原文地址:https://www.cnblogs.com/milk/p/2445734.html
Copyright © 2011-2022 走看看