Uncaught TypeError: Data[option] is not a function error occurred when using .datepicker('getDate')
Uncaught TypeError: Data[option] is not a function error occurred when using .datepicker('getDate')
我在尝试使用 .datepicker('getDate')
时遇到错误 data[option] is not a function
。
我使用这段代码来初始化日期选择器
<h4>Transaction Date:</h4>
From:
<input id="startDate" width="276" />
To:
<input id="endDate" width="276" />
<script type="text/javascript">
$(document).ready(function () {
$('#startDate').datepicker();
$('#endDate').datepicker();
</script>
但是当我使用这段代码试图获取日期选择器上设置日期的值时。
alert($('#endDate').datepicker('getDate'));
我收到一个错误 data[option] is not a function
尽管我的脚本上已经有一个 bootstrap-datepicker.js 而且我已经检查了我的 bootstrap-datepicker.js 它也有 getDate
的功能,所以现在我很难确定真正的问题是什么。
以下是包含的脚本:
bootstrap-datepicker.js
bootstrap.js
jquery-3.4.1.js
respond.js
您的代码有多个问题需要更正。
- 您正在使用
gijgo.min.js
和 bootstrap-datepicker.js
。
这两个库不能一起使用 datepicker()
因为冲突。要解决此问题,请删除其中一个。
- 您包含了不需要的库的
.min.js
和 .js
文件。您只能包含 .min.js
个文件并删除另一个。 .min.js
只是原始 .js
文件的缩小版本。
- 在
<script>
标签中包含这些库的顺序很重要。您应该始终首先包含诸如 jQuery 之类的依赖项,然后是 bootstrap,然后是依赖于这些库的其他依赖项。
我在尝试使用 .datepicker('getDate')
时遇到错误 data[option] is not a function
。
我使用这段代码来初始化日期选择器
<h4>Transaction Date:</h4>
From:
<input id="startDate" width="276" />
To:
<input id="endDate" width="276" />
<script type="text/javascript">
$(document).ready(function () {
$('#startDate').datepicker();
$('#endDate').datepicker();
</script>
但是当我使用这段代码试图获取日期选择器上设置日期的值时。
alert($('#endDate').datepicker('getDate'));
我收到一个错误 data[option] is not a function
尽管我的脚本上已经有一个 bootstrap-datepicker.js 而且我已经检查了我的 bootstrap-datepicker.js 它也有 getDate
的功能,所以现在我很难确定真正的问题是什么。
以下是包含的脚本:
bootstrap-datepicker.js
bootstrap.js
jquery-3.4.1.js
respond.js
您的代码有多个问题需要更正。
- 您正在使用
gijgo.min.js
和bootstrap-datepicker.js
。 这两个库不能一起使用datepicker()
因为冲突。要解决此问题,请删除其中一个。 - 您包含了不需要的库的
.min.js
和.js
文件。您只能包含.min.js
个文件并删除另一个。.min.js
只是原始.js
文件的缩小版本。 - 在
<script>
标签中包含这些库的顺序很重要。您应该始终首先包含诸如 jQuery 之类的依赖项,然后是 bootstrap,然后是依赖于这些库的其他依赖项。