比直接写HTML肯定是要慢的,只是少量的话,可能看不出来速度的慢。

解决方案 »

  1.   

    我的实际测试结果是document.writeln比较快
    我的测试方法是:
    test1.html------------------------------------------------------------------
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="javascript">
    var start = new Date().getTime();
    for(var i = 0;i <= 500; i ++){
    document.writeln('<input name="stype" type="radio" id="sight" checked>景点')
    document.writeln('<input type="radio" name="stype" id="pic">图片')
    document.writeln('<input type="radio" name="stype" id="article">游记')
    document.writeln('<input type="radio" name="stype" id="video">视频')
    document.writeln('<input type="radio" name="stype" id="map">地图')
    document.writeln('<input type="radio" name="stype" id="emap">电子地图')
    document.writeln('<input type="radio" name="stype" id="weather">天气')
    document.writeln('<input type="radio" name="stype" id="blogs">博客</td>')
    }
    var end = new Date().getTime();
    alert(end -start);
    </script>
    </head><body>
    </body>
    </html>test2.asp----------------------------------------------------------------------
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="javascript">
    var start = new Date().getTime();
    for(var i = 0;i <= 500; i ++){
    document.writeln('<input name="stype" type="radio" id="sight" checked>景点')
    document.writeln('<input type="radio" name="stype" id="pic">图片')
    document.writeln('<input type="radio" name="stype" id="article">游记')
    document.writeln('<input type="radio" name="stype" id="video">视频')
    document.writeln('<input type="radio" name="stype" id="map">地图')
    document.writeln('<input type="radio" name="stype" id="emap">电子地图')
    document.writeln('<input type="radio" name="stype" id="weather">天气')
    document.writeln('<input type="radio" name="stype" id="blogs">博客</td>')
    }
    var end = new Date().getTime();
    alert(end -start);
    </script>
    <input onkeypress="insert(this)">
    </head><body>
    9654
    </body>
    </html>
    ----------------------------------------------------------------------------
    结果分别是:
    次数        test1.html      test2.asp
     1            1622             1903
     2            1632             1683
     3            1633             1692
    ------加入随机参数---------------------
     1            1662             1762
     2            1663             1763
     3            1732             1803
     4            1742             1773
     5            1713             1912---------------------------------------
    波动应该是受我电脑的影响,但总体趋势很明显。...test1.html快
      

  2.   

    test2.asp(上面的发错了)
    --------------------------------------------------
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title></title>
    <script language="javascript">
    var start = new Date().getTime();
    </script>
    <%for i=0 to 500%>
    <input name="stype" type="radio" id="sight" checked>景点
    <input type="radio" name="stype" id="pic">图片
    <input type="radio" name="stype" id="article">游记
    <input type="radio" name="stype" id="video">视频
    <input type="radio" name="stype" id="map">地图
    <input type="radio" name="stype" id="emap">电子地图
    <input type="radio" name="stype" id="weather">天气
    <input type="radio" name="stype" id="blogs">博客</td>
    <%next%>
    <script language="javascript">
    var end = new Date().getTime();
    alert(end -start);
    </script>
    </head>
    <body>
    </body>
    </html>