javascript 对象中的 handleEvent


在高级浏览器中,我们在绑定事件的时候 可以知道绑定一个对象,然后在这个对象中的 handleEvent 方法会自动进入指定的方法,不多说了举个例子吧!!

var events = {
    handleEvent: function(event) {

          switch (event.type) {
            case 'touchstart': this.touchstart(event); break;
            case 'touchmove': this.touchmove(event); break;
            case 'touchend': touchend(event); break;
         }
    },
    touchstart:function(event){
    },
    touchmove:function(event){
    },
    touchend:function(event){
    }
}

document.getElementById('elementID').addEventListener('touchstart',events,false);
document.getElementById('elementID').addEventListener('touchmove',events,false);
document.getElementById('elementID').addEventListener('touchend',events,false);

这种在支持html5的浏览器中可以放心使用,wap端现在也可以放心使用,如果遇到版本低的浏览器就不能用这种了,因为低版本浏览器根不能用!!!!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM