2017-04-04 91 views
0

我實現波斯的DatePicker在WordPress通過建立一種插件無法讀取的不確定

這裏屬性「事件」是的DatePicker的庫:

http://babakhani.github.io/PersianWebToolkit/doc/datepicker/

,但是當我點擊瀏覽器檢查我看到控制檯此錯誤:

Uncaught TypeError: Cannot read property 'event' of undefined 
at persian-datepicker-0.4.5.min.js?ver=4.7.3:6 
at persian-datepicker-0.4.5.min.js?ver=4.7.3:7 

我也JQuery的庫後加載JS庫。

這裏是代碼:

jQuery(function ($) { 
//Datepicker 
if ($('.em-date-single, .em-date-range, #em-date-start').length > 0) { 
    em_setup_datepicker('body'); //Change class name to : .em-persian-date-start and .em-persian-date-end 
    $('.em-persian-date-start').pDatepicker({ 
     persianDigit: true, 
     viewMode: false, 
     position: "auto", 
     autoClose: false, 
     format: false, 
     observer: false, 
     altField: '.em-date-input', 
     inputDelay: 800, 
     formatter: function (unixDate) { 
      var self = this; 
      var pdate = new persianDate(unixDate); 
      pdate.formatPersian = false; 
      return pdate.format(self.format); 
     }, 
     altFormat: 'g', 
     altFieldFormatter: function (unixDate) { 
      var tzOffset = (new Date()).getTimezoneOffset() * 60000; 
      var self = this; 
      var thisAltFormat = self.altFormat.toLowerCase(); 
      if (thisAltFormat === "gregorian" | thisAltFormat === "g") { 
       return new Date(unixDate - tzOffset).toISOString().substring(0, 10).replace('T', ' '); 
      } 
      if (thisAltFormat === "unix" | thisAltFormat === "u") { 
       return unixDate; 
      } else { 
       return new persianDate(unixDate).format(self.altFormat); 
      } 
     }, 
     onSelect: function (unixDate) { 
      return this; 
     }, 
     timePicker: { 
      enabled: true, 
      showSeconds: true, 
      showMeridian: true, 
      scrollEnabled: true 
     }, 
     dayPicker: { 
      enabled: true, 
      scrollEnabled: true, 
      titleFormat: 'YYYY MMMM', 
      onSelect: function (selectedDayUnix) { 
       setEndDate(selectedDayUnix); 
      } 

     }, 
     onlyTimePicker: false, 
     justSelectOnDate: true, 
     minDate: false, 
     maxDate: false 
    }); //init datePicker 
} 
}); 
+0

是否'$ length'不是返回0。? – Justinas

+0

是的,它按預期返回1 – Adnan

回答

0

在WordPress中,我們不能使用$,我們必須使用的,而不是 '$' 'jQuery的'。

例如:( 'EM-波斯日期開始')

var len = jQuery('.classname').length;