Vivianluolita 2016-11-03 08:28 采纳率: 0%
浏览 1217

同一个div不能绑定多个事件么?为什么我的touch能用之后click不能用呢?

     /*图片复选功能*/
        $(".TabListItem .ForFun").click(function(){
            //如果已经被选中
            if($(this).hasClass("AddImg")){
                $(this).removeClass("AddImg");
            }
            //如果没被选中
            else{
                $(this).addClass("AddImg");
            }
        });


        /*touch事件*/


        $(".ForFun").on({
            touchstart: function(e){
                timeOutEvent = setTimeout("longPress()",500);
                e.preventDefault();
                return false;
            },
            touchmove: function(){
                clearTimeout(timeOutEvent);
                timeOutEvent = 0;
            },
            touchend: function(e){
                clearTimeout(timeOutEvent);
                timeOutEvent = ShortLeave();
                e.preventDefault();
                return false;

            }
        })
    });
  • 写回答

2条回答 默认 最新

  • 俊刚、 2016-11-03 11:02
    关注

    可以绑定多个事件的。
    例:

     <!DOCTYPE html>
    <html>
    <body>
    
    <div onmouseover="mOver(this)" onmouseout="mOut(this)" onclick="this.innerHTML='再见!'" style="background-color:green;width:120px;height:20px;padding:40px;color:#ffffff;">把鼠标移到上面</div>
    
    <script>
    function mOver(obj)
    {
    obj.innerHTML="谢谢"
    }
    
    function mOut(obj)
    {
    obj.innerHTML="把鼠标移到上面"
    }
    
    
    </script>
    
    </body>
    </html>
    
    
    评论

报告相同问题?