实现类似Excel那样 按住鼠标单击键,移动鼠标可以划块选择,松开后代表选择完成。
就想桌面那样 按住单击键可以拉一个方框。
onclick不行,这个是单击后,单击键松开后才触发
onmoucedown也好像不行,这个右键也能触发事件。HTML鼠标JavaScript单击事件划块选择

解决方案 »

  1.   

    或者用onmoucedown这个事件,只要能判断出按得是单击键就行,
    有什么方法能判断吗?
      

  2.   

    onmousedown 按下鼠标
    onmousemove 鼠标在元素内部移动
    onmouseup 松开鼠标
    是不是右键触发用event.button判断
    IE下
    没有按键动作的时候 window.event.button = 0
    左键是 window.event.button = 1
    中键是 window.event.button = 4
    右键是 window.event.button = 2
    Firefox下
    没有按键动作的时候 event.button = 0
    左键是 event.button = 0
    中键是 event.button = 1
    右键是 event.button = 2
      

  3.   

    就按楼上说的 判断event.button的值