Javascript在IE上画VML polyline多边型

<HTML xmlns:v>
 <STYLE>v\:*{behavior:url(#default#VML);position:absolute;}
 </STYLE>
 <script language="javascript">  
  var begindraw = 1;
  var moveing = 0;

  var ap_startx = 0;
  var ap_starty = 0;
  var ap_index = 0;
  
  function Point(){
   this.x = -1;
   this.y = -1;
  }
  
  var ap_pnts = new Array();
  var ap_cltpnts = new Array();
  
  document.onmousedown = function (){
   if(event.button==1){
    if (begindraw==1 && moveing==0) {
     ap_startx = event.x;
     ap_starty = event.y;
     strElement="<v:polyline id='IR' style='position: absolute;top:"+ap_starty+";left:"+ap_startx+";' points='0,0' Filled='False' filled='t' strokecolor='blue' />";
     document.body.insertAdjacentHTML('beforeend', strElement);
     
     moveing = 1;
     ap_pnts[ap_index] = new Point();
     ap_pnts[ap_index].x = 0;
     ap_pnts[ap_index].y = 0;
     ap_cltpnts[ap_index] = new Point();
     ap_cltpnts[ap_index].x = event.x;
     ap_cltpnts[ap_index].y = event.y;
    }
    else if (begindraw==1 && moveing==1) {
     var xp = event.x - ap_startx;
     var yp = event.y - ap_starty;
     ap_index++;
     
     ap_pnts[ap_index] = new Point();
     ap_pnts[ap_index].x = xp;
     ap_pnts[ap_index].y = yp;
     ap_cltpnts[ap_index] = new Point();
     ap_cltpnts[ap_index].x = event.x;
     ap_cltpnts[ap_index].y = event.y;
     document.getElementById('IR').points.value = document.getElementById('IR').points.value + ',' + ap_pnts[ap_index].x + ',' + ap_pnts[ap_index].y;
     
     for(var i=0;i<=ap_index;i++)
      document.getElementById('IR').points(i) = ap_pnts[i].x + ',' + ap_pnts[i].y;
    }
   }
   else{
    if (document.getElementById('IR')!=null && begindraw==1) {   
     ap_index++;
      
     ap_pnts[ap_index] = new Point();
     ap_pnts[ap_index].x = 0;
     ap_pnts[ap_index].y = 0;
     
     document.getElementById('IR').points.value = document.getElementById('IR').points.value + ',0,0';
     for(var i=0;i<=ap_index;i++)
      document.getElementById('IR').points(i) = ap_pnts[i].x + ',' + ap_pnts[i].y;

     ap_cltpnts[ap_index] = new Point();
     ap_cltpnts[ap_index].x = ap_cltpnts[0].x;
     ap_cltpnts[ap_index].y = ap_cltpnts[0].y;
      
     begindraw = 0;
     
     for(var i=0;i<=ap_index;i++)
      ap_pnts.pop();
     for(var i=0;i<=ap_index;i++)
      alert(ap_cltpnts[i].x+','+ap_cltpnts[i].y);
     for(var i=0;i<=ap_index;i++)
      ap_cltpnts.pop();
     
    }
   }
  }
  
  document.onmousemove = function (){
   window.status = event.x + ',' + event.y;
  }
  
  document.oncontextmenu = function(){
   return false;
  }
 </script>
 <BODY>
 </BODY></HTML>

你可能感兴趣的:(JavaScript)