首页 > 网站 > WEB开发 > 正文

javascript 对象中的 handleEvent

2024-04-27 14:14:35
字体:
来源:转载
供稿:网友

javascript 对象中的 handleEvent

Posted on 2014-12-29 17:55 绝交 阅读(...) 评论(...) 编辑 收藏

在高级浏览器中,我们在绑定事件的时候 可以知道绑定一个对象,然后在这个对象中的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端现在也可以放心使用,如果遇到版本低的浏览器就不能用这种了,因为低版本浏览器根不能用!!!!


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表