我正在通过开发插件在WordPress中实现波斯语DatePicker
这是DatePicker的库:
http://babakhani.github.io/PersianWebToolkit/doc/datepicker/
但是当我在浏览器中点击inspect时,我在控制台上看到了这个错误:
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 Lib之后加载了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 :(得分:0)
在WordPress中我们不能使用$,我们必须使用' jQuery'而不是' $'。
例如:
var len = jQuery('.classname').length;