-3

我正在對MVC上的項目進行工作,其中我在表單字段中添加了日期時間選擇器,用於我已下載的bootstrap-datetimepicker引導程序中未捕獲的引用錯誤datetimepicker

我已經提取JSCSS文件到我的項目,但仍然顯示一些錯誤。

錯誤是:

VM199:2 Uncaught ReferenceError: moment is not defined 
    at HTMLDocument.eval (eval at globalEval (jquery-2.1.4.js:328), <anonymous>:2:42) 
    at fire (jquery-2.1.4.js:3099) 
    at Object.add [as done] (jquery-2.1.4.js:3145) 
    at jQuery.fn.init.jQuery.fn.ready (jquery-2.1.4.js:3378) 
    at jQuery.fn.init (jquery-2.1.4.js:2821) 
    at jQuery (jquery-2.1.4.js:76) 
    at eval (eval at globalEval (jquery-2.1.4.js:328), <anonymous>:1:1) 
    at eval (<anonymous>) 
    at Function.globalEval (jquery-2.1.4.js:328) 
    at jQuery.fn.init.domManip (jquery-2.1.4.js:5435) 
+0

似乎你還沒有在你的頁面中加入「moment.js」嗎? –

+0

你的代碼使用['moment.js'](https://momentjs.com/),但是這不包含在頁面中。 – 31piy

+0

僅使用moment.js的cdn查看它是否正常工作,請確保在使用之前加載了moment.js。 –

回答

0

自舉的DateTimePicker正常工作,下面的一組需要在標籤

> jQuery 
> Moment.js 
> Bootstrap.js (transition and collapse features are required if you're not using the full Bootstrap) 
> Bootstrap Datepicker script 
> Bootstrap CSS 
> Bootstrap Datepicker CSS 

添加的文件的請初始化的DateTimePicker

$("#fromDate").datetimepicker({ 
       sideBySide: true, 
       debug:false, 
       useCurrent: false, 
       format: 'YYYY-MM-DD HH:mm:ss' 
       }) 

<div class="input-group date" id="fromDate"> 
        <input type="text" class="form-control" name="fromDate"/> 
        <span class="input-group-addon"> 
         <span class="glyphicon glyphicon-calendar"></span> 
        </span> 
       </div> 

DateTimepicker有很多可定製的功能。要了解更多信息,請參閱t他DateTimePicker

0

我解決了我的錯誤,這是由於在代碼中的其他地方定義的重複函數。