2015-06-08 224 views
0

我正在做一個傳單插件,我對日曆有問題。Uncaught TypeError:undefined不是函數

var calen = L.DomUtil.create('div', className, container); 
    calen.href = '#'; 
    L.DomEvent 
     .addListener(calen, 'click', L.DomEvent.stopPropagation) 
     .addListener(calen, 'click', L.DomEvent.preventDefault) 
     .addListener(calen, 'click', this._buttonExtendCalendaClicked, this); 

    calen.datepicker({ 
     changeMonth: true, 
     changeYear: true, 
     altField: '#date-input', 
     altFormat: 'mm/dd/yy', 
     defaultDate: new Date().getTime() 
    }); 

的錯誤是:遺漏的類型錯誤:未定義是不是一個函數

我不知道我該怎麼辦呢

+0

調試程序會告訴您問題出在哪一行? –

+0

calen.datepicker({ – Alba

回答

0

calen由單張的DomUtil.create()它返回一個HTMLElement

初始化

jqueryui將它的小部件定義爲jquery插件,因此您需要將HTMLElement包裝在jquery集合中:

$(calen).datepicker({ /* ... options ... */ }); 
+0

)謝謝,我很愚蠢 – Alba

+0

這是一個常見的錯誤,尤其是如果你不是很熟悉這些庫。如果答案幫助你考慮[ticking it](http://stackoverflow.com /幫助/人,答案) – blgt

相關問題