OGeek|极客世界-中国程序员成长平台

标题: jQuery datepicker 需要长按才能在 iPhone 中打开 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 14:37
标题: jQuery datepicker 需要长按才能在 iPhone 中打开

如何在 iPhone 中一键打开日期选择器?

在桌面和 Android 上都很好;只有在 iPhone 中我才需要长按或点击多次。

这是我的脚本:

jQuery(".calendar-pick").datepicker({dateFormat: 'dd M, yy',minDate: 0});



Best Answer-推荐答案


var pressTimer;
//put below click if resolution is IPHONE long press on anchor link or textbox it will open after 2 secs 
$(".calendar-pick, a").mouseup(function(){
  clearTimeout(pressTimer);
  // Clear timeout
  return false;
}).mousedown(function(){
  // Set timeout
  pressTimer = window.setTimeout(function() {
  //your code goes here first
    $(".calendar-pick").datepicker("destroy");
    $(".calendar-pick").datepicker({dateFormat: 'dd M, yy',minDate: 0});
    $(".calendar-pick").focus();
  
  },2000);
  return false; 
});

$(function(){
$(".calendar-pick").datepicker({dateFormat: 'dd M, yy',minDate: 0});
})
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>
<a href="#" >Hello</a>
<input  class="calendar-pick" type="text" />

关于jQuery datepicker 需要长按才能在 iPhone 中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41950667/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4