不知道js能否捕获按下鼠标滚轮键的事件呢?麻烦写一个.多谢!

解决方案 »

  1.   

    你在事件的函数里判断下e.button不行吗
      

  2.   

    记得以前试的时候IE和FF获取中键的button值好像不一样,楼主要注意一下
      

  3.   

    恩 一个是1  一个是4
    但是左键和右键确定了 ELSE就是中键呗
      

  4.   

    <script type="text/javascript">
    function test(evt){
        if(evt){
           if(evt.button == 1) {
              alert("请在这里处理事件");
           }
        }
        else{
           if(window.event.button == 4){
             alert("请在这里处理事件");
           }    }
    }
      </script>
    <div id="d1" style="background:red;height:50px;width:50px;" onmousedown="test(event);">测试滚轮事件</div>
      

  5.   

    为什么这么喜欢if-else,还臃肿啊<script type="text/javascript">
        function test(evt){
    var evt = evt || window.event; //就两行代码而已,为什么要写那么多
    if(evt.button == 1 || evt.button == 4){
    alert("这里");
    }
    }
    </script>
    <div id="d1" style="background:red;height:50px;width:50px;" onmousedown="test(event);">