查看: 227|回复: 0

[文章教程] JQ模拟双击代码

[复制链接]
xuanxiao 发表于 2023-9-5 19:01:11 | 显示全部楼层 |阅读模式
  1. var touchtime = 0;
  2. $(".target").on("click", function() {
  3.     if (touchtime == 0) {
  4.         // set first click
  5.         touchtime = new Date().getTime();
  6.     } else {
  7.         // compare first click to this click and see if they occurred within double click threshold
  8.         if (((new Date().getTime()) - touchtime) < 800) {
  9.             // double click occurred
  10.             alert("double clicked");
  11.             touchtime = 0;
  12.         } else {
  13.             // not a double click so set as a new first click
  14.             touchtime = new Date().getTime();
  15.         }
  16.     }
  17. });
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表

在线客服

售前咨询
售后咨询
服务热线
023-58418553
微信公众号