• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
致逝去
博客园    首页    新随笔    联系   管理    订阅  订阅

长按按钮事件函数

这里是代码的逻辑编写部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$.fn.longPress = function(fn) {
        var timeout = undefined;
        var $this = this;
        alert(this.length);
        for(var i = 0;i<$this.length;i++){
            $this[i].addEventListener('touchstart', function(event) {
                timeout = setTimeout(fn, 800);
                }, false);
            $this[i].addEventListener('touchend', function(event) {
                clearTimeout(timeout);
                }, false);
        }
        }
  

代码的代用部分,其中select是你所要获取的元素

1
2
3
$(select).longPress(function(index){
      alert("你已长按");
  });
posted @ 2016-12-02 19:33  致逝去  阅读(368)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3