那请问有程序吗?希望能给我一个![email protected]

解决方案 »

  1.   

    <BODY>
    <div id=div1></div><SCRIPT LANGUAGE="JavaScript">
    <!--
    div1.innerHTML = drawLine(100,100,500,300,"red");
    document.writeln("<style>");
    document.writeln(".emuW{position:absolute;font-size:1px;width:1}");
    document.writeln(".emuH{position:absolute;font-size:1px;height:1}");
    document.writeln(".emuWH{position:absolute;font-size:1px;width:1;height:1}");
    document.writeln("A{text-decoration:none;color:#FF66FF}");
    document.writeln("</style>");
    function drawLine(x0,y0,x1,y1,color){
    x0 = Math.round(x0);
    x1 = Math.round(x1);
    y0 = Math.round(y0);
    y1 = Math.round(y1);
    var rs = "";
    if (y0 == y1){  //&raquo;&shy;&ordm;á&Iuml;&szlig;
    if (x0>x1){var t=x0;x0=x1;x1=t}  
    rs = "<img border=0 class=emuH style='top:"+y0+";left:"+x0+";background-color:"+color+"; width:"+Math.abs(x1-x0)+"'/>";
    }
    else if (x0 == x1){  //&raquo;&shy;&Ecirc;ú&Iuml;&szlig;
    if (y0>y1){var t=y0;y0=y1;y1=t} 
    rs = "<img border=0 class=emuW style='top:"+y0+";left:"+x0+";background-color:"+color+";height:"+Math.abs(y1-y0)+"'/>";
    }
    else{
    var lx = x1-x0;
    var ly = y1-y0;
    if (Math.abs(lx)>Math.abs(ly)){
    if (ly<0){
    var t=x0;x0=x1;x1=t;
    t=y0;y0=y1;y1=t;
    lx = -lx;
    ly = -ly;
    }
    var dx = lx/ly;
    rs = new Array(ly);
    for (var i=0;i<ly;i++){
    var left,width;
    if (dx>0){
    left = Math.round(i*dx);
    width = Math.round((i+1)*dx)-left;
    left += x0;
    if (width+left>x1) width = x1-left;
    }else{
    left = Math.round((i+1)*dx);
    width = Math.round((i)*dx)-left;
    left += x0;
    if (left<x1) {
    width = width+left-x1;
    left=x1;
    }
    }
    rs[i] = "<img border=0 class=emuH style='top:"+(y0+i)+";left:"+left+";width:"+width+";background-color:"+color+"'/>";
    }
    }else{
    if (lx<0){
    var t=x0;x0=x1;x1=t;
    t=y0;y0=y1;y1=t;
    lx = -lx;
    ly = -ly;
    }
    var dy = ly/lx;
    rs = new Array(lx);
    for (var i=0;i<lx;i++){
    var top,height;
    if (dy>0){
    top = Math.round(i*dy);
    height = Math.round((i+1)*dy)-top;
    top += y0;
    if (height+top>y1) height = y1-top;
    }else{
    top = Math.round((i+1)*dy);
    height = Math.round((i)*dy)-top;
    top += y0;
    if (top<y1) {
    height = height+top-y1;
    top=y1;
    }
    }
    rs[i] = "<img border=0 class=emuW style='top:"+top+";left:"+(x0+i)+";height:"+height+";background-color:"+color+"'/>";
    }
    }
    rs = rs.join("");
    }
    return rs
    }//-->
    </SCRIPT>
    </BODY>呵呵,晕了没?div1.innerHTML = drawLine(100,100,500,300,"red");这一句可以改坐标和颜色。