[英]$().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.