我在控制台中看到未捕获的错误,请帮助我
bootstrap-datepicker.js:1679 Uncaught Error: Using only allowed for the collection of a single element (getFormattedDate function)
at w.fn.init.datepickerPlugin [as datepicker] (bootstrap-datepicker.js:1679)
at HTMLInputElement.<anonymous> (common.js:369)
at HTMLInputElement.dispatch (jquery-3.3.1.min.js:2)
at HTMLInputElement.y.handle (jquery-3.3.1.min.js:2)
at Object.trigger (jquery-3.3.1.min.js:2)
at HTMLInputElement.<anonymous> (jquery-3.3.1.min.js:2)
at Function.each (jquery-3.3.1.min.js:2)
at w.fn.init.each (jquery-3.3.1.min.js:2)
at w.fn.init.trigger (jquery-3.3.1.min.js:2)
at Datepicker._trigger (bootstrap-datepicker.js:460)
答案 0 :(得分:0)
我遇到了同样的错误
发生这种情况是因为您的jquery选择器不是唯一的,并且包含多个datepickers元素,因此该插件无法理解如何返回日期
确保选择器中只有一个元素
$('.datepicker').get(0).datepicker('getDate')
或者使用foreach
$('.datepicker').each(function() {
var date = this.datepicker('getDate'); //Do something with the date
}