呵呵,开个玩笑,别介意! 
主要是要交流嘛..  :P
我写了一个给你
===============================
<script language="JavaScript">
function Point(x,y) {  this.x = x; this.y = y; }
var mouseLocation = new Point(-500,-500);
var downLocation = null;function getMouseLoc(e)
{
  if(!document.all)  //NS
  {
    mouseLocation.x = e.pageX;
    mouseLocation.y = e.pageY;
  }
  else               //IE
  {
    mouseLocation.x = event.x + document.body.scrollLeft;
    mouseLocation.y = event.y + document.body.scrollTop;
  }
  return true;
}if(document.layers){ document.captureEvents(Event.MOUSEMOVE);}function doMouseDown(){
if (document.layers) getMouseLoc;     //NS
else if (document.all) getMouseLoc(); //IE
downLocation=new Point(mouseLocation.x,mouseLocation.y)
}
function doMouseUp(){
downLocation=null;
Layer1.style.visibility="hidden";
}
function doResize(){
if (downLocation==null) return;

if (document.layers) getMouseLoc;     //NS
else if (document.all) getMouseLoc(); //IE Layer1.style.left=(downLocation.x<=mouseLocation.x)?downLocation.x:mouseLocation.x;
Layer1.style.top=(downLocation.y<=mouseLocation.y)?downLocation.y:mouseLocation.y;
var theWidth=Math.abs(downLocation.x-mouseLocation.x);
var theHeight=Math.abs(downLocation.y-mouseLocation.y);
Layer1.style.width=theWidth
Layer1.style.height=theHeight;
if (Layer1.style.visibility!="visible") Layer1.style.visibility="visible";
}
</script>
<body onMouseMove="doResize();" onMouseDown="doMouseDown();" onMouseUp="doMouseUp();" ondragstart="return false">
<div id="Layer1" style="position:absolute;width:10px;height:10px;visibility:hidden;border:1px dotted #666666;overflow:hidden;"></div>
</body>

解决方案 »

  1.   

    to:一只T小猫
    我想在一张图片上画一个矩形层,加了张图片怎么就不可以了呢?
    还有我想只针对鼠标左键有效,怎么实现呢?
      

  2.   

    我的意思是:
    <body>
    <img src="yy.jpg" onMouseMove="doResize();" onMouseDown="doMouseDown();" onMouseUp="doMouseUp();" ondragstart="return false">
    ......
    就不行了????
    我想按下右键不想拉出这个矩形框
      

  3.   

    <body onMouseMove="doResize();" onMouseDown="doMouseDown1();"
     onMouseUp="doMouseUp();" ondragstart="return false">
    <script>
    function doMouseDown1()
    {
     if (event.button==1) doMouseDown();
    }</script>
      

  4.   

    <img src="yy.jpg" onMouseMove="doResize();" onMouseDown="doMouseDown();" onMouseUp="doMouseUp();" ondragstart="return false">
    看我要实现的是否有些冲突:
    1:按下鼠标左键并拖动可以拉出矩形框,放开左键矩形框消失
    2:不按下鼠标任何键且鼠标移动时在状态栏显示鼠标的位置
    上述鼠标的动作是在yy.jpg上操作的,离开yy.jpg所有操作失效不知如何实现??