2015-12-01 32 views
0

因此,我使用的是​​,我試圖從任何pickadate事件處理函數中引用DOM中的日期對象。引用內部事件處理函數中的當前DOM元素(pickadate.js)

例如,我希望能夠說:

onClose: function() { 
    var $this = ?; // <-- How do I define $this? 
    $this.fadeOut(); 
} 

問:

如何從裏面的這些事件處理功能之一是指當前的DOM元素?

注:

this, $(this) and $this don't seem to work :-(

代碼:

var dates = $('.dates'); 

dates.pickadate({ 
    today: t, 
    format: f, 
    clear: false, 
    min: min, 
    max: max, 
    selectYears: sy, 
    selectMonths: sm, 
    firstDay: fd, 
    formatSubmit: f2, 
    hiddenSuffix: s, 

    onClose: function() { 
     var $this = ?; // <-- How do I define $this? 
     $this.fadeOut(); 
    } 
}); 
+1

你可以添加你的html和js代碼嗎? – Pedram

+0

嗯...我發現這個'在所有這六個事件的範圍內,這是指picker.'在這個頁面的末尾http://amsul.ca/pickadate.js/date/ –

回答

1

試試這個:

onClose: function() { 
    this.trigger().$node.fadeOut() 
} 
+0

你也可以在函數的第一行寫上「debugger」語句並使用「chrome開發工具」來實現更好的解決方案: onClose:function(){ debugger; this.trigger()。$ node.fadeOut() } – Pedram

1

基於對返回的對象,我懷疑你正在尋找的是:

onClose: function() { 
    var $this = this.$holder; 
    $this.fadeOut(); 
} 
+0

你絕對的在那裏的東西。這個。$ root.parent()。hide()成功隱藏了pickadate元素的父容器。 $ holder.parent()。parent()。hide(); –

+0

所以你說的是這個。$ root實際上是你在找什麼?意思是,在datepicker.js事件中,this = this。$ root?如果你知道了,也許你可以自己發佈問題的答案;) – 1cgonza

+0

http://amsul.ca/pickadate.js/api/#objects –

相關問題