2014-01-09 46 views
-2

任何人都可以幫助我將此函數轉換爲jQuery 1.8.3的live/on版本嗎?將函數轉換爲Live/On(jQuery)

我們從數據庫中動態加載視頻並將其附加到頁面上的HTML中。 這段代碼顯示視頻下方文本信息的更多/更少。 (喜歡YT。)

到目前爲止,我試過的每一個都沒有使這個函數在附加內容中工作。

$(".showmore").toggle(function(){ 
    $(this).text("- show less -").siblings(".complete").show();  
}, function(){ 
    $(this).text("- read more -").siblings(".complete").hide();  
}); 
+0

你缺少一個事件綁定其餘版本的可視性,這是相同的jquery 1.8.3 – voigtan

+1

僅供參考:['.toggle()'事件](http://api.jquery.com/toggle-event/)在1.8中被棄用,在1.9中被刪除。 –

+0

@voigtan:這是一個事件綁定。他想要將事件委託給他。 –

回答

2

那的toggle()版本中刪除,但是您可以切換與回調的文本,並與toggle()

$(document).on('click', '.showmore', function() { 
    $(this).text(function(_, txt) { 
     return txt == '- show less -' ? '- read more -' : '- show less -'; 
    }).siblings('.complete').toggle(); 
}); 
+0

非常感謝!你解決了我的問題! – KJS