[英]$().live is not a function - JavaScript/jQuery
在Firefox中,我突然從螢火蟲收到了此消息:
$('a.close, #fade').live is not a function
確實,當我單擊圖庫並彈出顯示時。 我不能關閉它。 由於此錯誤消息,單擊事件永遠不會注冊。
這是腳本:
$('a.poplight[href^=#]').click(function() {
var popID = $(this).attr('rel');
var popURL = $(this).attr('href');
var query= popURL.split('?');
var dim= query[1].split('&');
var popWidth = dim[0].split('=')[1];
//Fade in the Popup and add close button
var div_popup = document.createElement('div');
div_popup.setAttribute('id',popID);
div_popup.setAttribute('class','popup_block');
document.body.appendChild(div_popup);
$(div_popup).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a> <a href="thumbBg' + $(this).attr('rel').substring($(this).attr('rel').lastIndexOf('p') + 1,$(this).attr('rel').length) + '"></a><p>The Human Diet: By Rene Endara</p>');
var popMargTop = ($('#' + popID).height() + 80) / 2;
var popMargLeft = ($('#' + popID).width() + 80) / 2;
$('#' + popID).css({
'margin-top' : -popMargTop,
'margin-left' : -popMargLeft
});
$('body').append('<div id="fade"></div>');
$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
return false;
});
//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() {
$('#fade , .popup_block').fadeOut(function() {
$('#fade, a.close').remove(); //fade them both out
});
return false;
});
標記:
<ul class="thumb">
<li><a href="#?w=500" rel="popup1" class="poplight"><img src="images/thumb1.jpg" alt="" /></a></li>
<li><a href="#?w=500" rel="popup2" class="poplight"><img src="images/thumb2.jpg" alt="" /></a></li>
<li><a href="#?w=500" rel="popup3" class="poplight"><img src="images/thumb3.jpg" alt="" /></a></li>
<li><a href="#?w=500" rel="popup4" class="poplight"><img src="images/thumb4.jpg" alt="" /></a></li>
</ul>
感謝您的回復。
由於從jQuery 1.7+開始不推薦使用.live()
,因此您必須使用.on()
或.delegate()
。
參見相關問題jQuery 1.9 .live()不是有關如何遷移現有代碼的函數 。
.live()
是jQuery 1.3中引入的,因此它不適用於早期版本。
自從jQuery 1.7開始不推薦使用.live()
。
替代方案是.on()
和.delegate()
參見相關問題jQuery 1.9 .live()不是有關如何遷移現有代碼的函數 。
Tente Usar .bind
no lugar de .live
嘗試使用.bind
而不是.live
對於使用> = v1.9的其他用戶,請參見此處有關折舊的信息: jQuery 1.9 .live()不是函數
在wp-includes \\ js \\ thickbox \\ thickbox.js中找到此功能並更改功能:
function tb_init(domChunk){
jQuery(domChunk).live('click', tb_click);
}
將“ live”方法替換為“ on”,如下所示:
function tb_init(domChunk){
jQuery(domChunk).on('click',tb_click);
}
如果您使用的是Nivo-Slider,則jquery.nivo.slider.js將需要進行類似的更改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.