HTML5 date picker doesn't show on Safari

前端 未结 6 1928
星月不相逢
星月不相逢 2021-02-02 05:13

Having previously used jQuery date picker, I have now converted some of the date fields in forms on my website to the HTML5 date picker.

On the documentation, it says Sa

6条回答
  •  情深已故
    2021-02-02 05:35

    Taken from http://www.javascriptkit.com/javatutors/createelementcheck2.shtml

    With jQuery and jQuery UI you can create a crossbrowser datepicker that only pops up when the browser doesn't support it natively. If you already have jQuery in your project, simply do:

    var dateClass='.datechk';
    $(document).ready(function ()
    {
      if (document.querySelector(dateClass).type !== 'date')
      {
        var oCSS = document.createElement('link');
        oCSS.type='text/css'; oCSS.rel='stylesheet';
        oCSS.href='//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/base/jquery-ui.css';
        oCSS.onload=function()
        {
          var oJS = document.createElement('script');
          oJS.type='text/javascript';
          oJS.src='//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js';
          oJS.onload=function()
          {
            $(dateClass).datepicker();
          }
          document.body.appendChild(oJS);
        }
        document.body.appendChild(oCSS);
      }
    });
    
    

提交回复
热议问题