<html>
<head><title></title></head>
<body>
<style type="text/css">
.dp {position:absolute; width:1px; height:1px; overflow:hidden; background-color:#666666}
</style>
<script language="javascript">// Author:张郎 winer_n 
function drawOval(x, y, a, b) 

    if(arguments.length == 3) 
    { 
        return drawOval(x, y, a, a); 
    } 
    var i, j; 
    var tpos = []; 
    var x1, x2, y1, y2; 
    var html = ""; 
    for(i = 0; i <= a; i++) 
    { 
        j = Math.floor(Math.sqrt(b*b - b*b*i*i/(a*a))+0.5); 
        x1 = i+x; 
        x2 = -i+x; 
        y1 = j+y; 
        y2 = -j+y; 
        if(!tpos[x1*1000+y1]) 
        { 
            drawPos(x1,y1); 
            drawPos(x1,y2); 
            drawPos(x2,y1); 
            drawPos(x2,y2); 
            tpos[x1*1000+y1] = true; 
        } 
    } 
    for(i = 0; i <= b; i++) 
    { 
        j = Math.floor(Math.sqrt(a*a - a*a*i*i/(b*b))+0.5); 
        x1 = j+x; 
        x2 = -j+x; 
        y1 = i+y; 
        y2 = -i+y; 
        if(!tpos[x1*1000+y1]) 
        { 
            drawPos(x1,y1); 
            drawPos(x1,y2); 
            drawPos(x2,y1); 
            drawPos(x2,y2); 
            tpos[x1*1000+y1] = true; 
        } 
    } 
    document.write(html);     function drawPos(x, y) 
    { 
        html += "<div class='dp' style='left:" + x + "px; top:" + y + "px;'></div>"; 
    } } var t = new Date(); 
drawOval(200, 200, 100); // 圆 
drawOval(300, 300, 200, 100); // 椭圆 
alert(new Date() - t);
</script>
</body>
</html>

解决方案 »

  1.   

    <html> 
    <head> <title> </title> </head> 
    <body> 
    <style type="text/css"> 
    .dp {position:absolute; width:1px; height:1px; overflow:hidden; background-color:#666666} 
    </style> 
    <script language="javascript"> // Author:张郎 winer_n 
    function drawOval(x, y, a, b) 

        if(arguments.length == 3) 
        { 
            return drawOval(x, y, a, a); 
        } 
        var i, j; 
        var tpos = []; 
        var x1, x2, y1, y2; 
        var html = ""; 
        for(i = 0; i <= a; i++) 
        { 
            j = Math.floor(Math.sqrt(b*b - b*b*i*i/(a*a))+0.5); 
            x1 = i+x; 
            x2 = -i+x; 
            y1 = j+y; 
            y2 = -j+y; 
            if(!tpos[x1*1000+y1]) 
            { 
                drawPos(x1,y1); 
                drawPos(x1,y2); 
                drawPos(x2,y1); 
                drawPos(x2,y2); 
                tpos[x1*1000+y1] = true; 
            } 
        } 
        for(i = 0; i <= b; i++) 
        { 
            j = Math.floor(Math.sqrt(a*a - a*a*i*i/(b*b))+0.5); 
            x1 = j+x; 
            x2 = -j+x; 
            y1 = i+y; 
            y2 = -i+y; 
            if(!tpos[x1*1000+y1]) 
            { 
                drawPos(x1,y1); 
                drawPos(x1,y2); 
                drawPos(x2,y1); 
                drawPos(x2,y2); 
                tpos[x1*1000+y1] = true; 
            } 
        } 
        document.write(html);     function drawPos(x, y) 
        { 
            html += " <div class='dp' style='left:" + x + "px; top:" + y + "px;'> </div>"; 
        } } //var t = new Date(); 
    //drawOval(200, 200, 100); // 圆 
    //drawOval(300, 300, 200, 100); // 椭圆 
    //alert(new Date() - t); 
    </script> 
    <form id="form1">
        <input type="button" id="button1" value="圆" onclick="drawOval(200,200,100)" />
    </form>
    </body> 
    </html>
    这样为什么就不行呢?我想要一个按钮控制画圆的额???
      

  2.   

    divdraw.innerHTML=drawLine(150,250,450,300,"red")+drawLine(350,150,509,450,"black"); 你用的是write这样页面就重新生成了,还是用innerHTML赋值来测试吧。