控制台无法将日期选择器识别为功能

时间:2020-11-01 20:22:32

标签: javascript jquery jquery-ui

我在项目中包含了jquery-ui.css,jquery-ui.js和jquery-3.2.1.min.js文件,但仍然出现以下错误

"$("#ClaimExpenseDate_" + RowCount).datepicker" is not a function

$("#ClaimExpenseDate_" + RowCount).datepicker({
    maxDate: maxDate,
    dateFormat: "dd/mm/yy"
});

1 个答案:

答案 0 :(得分:0)

也许此时jQuery尚未完全加载,您确定之前未调用过代码吗?也许该元素不存在或未加载。

您可以尝试使用这种语法吗?

 $( function() {
    const elem = $("#ClaimExpenseDate_" + RowCount);
    console.log('Elem exists?', elem);
    console.log('datepicker exists?', elem.datepicker);
    elem.datepicker({
      maxDate: maxDate,
      dateFormat: "dd/mm/yy"
    });
 });

关于JQuery loaded twice

还有另一个奇怪的错误