简体   繁体   English

$()。live不是函数-JavaScript / jQuery

[英]$().live is not a function - JavaScript/jQuery

In Firefox I suddenly got this message from firebug: 在Firefox中,我突然从萤火虫收到了此消息:

$('a.close, #fade').live is not a function

Indeed, when I click the image gallery and popup displays. 确实,当我单击图库并弹出显示时。 I cannot close out of it. 我不能关闭它。 The click event never registers due to this error message. 由于此错误消息,单击事件永远不会注册。

This is script: 这是脚本:

        $('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;
    });

markup: 标记:

    <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>

Thanks for response. 感谢您的回复。

http://api.jquery.com/live/ http://api.jquery.com/live/

Since .live() is deprecated as of jQuery 1.7+, you have to use either .on() or .delegate() . 由于从jQuery 1.7+开始不推荐使用.live() ,因此您必须使用.on().delegate()

See related question jQuery 1.9 .live() is not a function on how to migrate existing code. 参见相关问题jQuery 1.9 .live()不是有关如何迁移现有代码的函数

.live() was introduced in jQuery 1.3 , therefore it won't work with earlier versions. .live()jQuery 1.3中引入的,因此它不适用于早期版本。

.live() has also since been deprecated in jQuery 1.7 onwards. 自从jQuery 1.7开始不推荐使用.live()

The alternatives are .on() and .delegate() 替代方案是.on().delegate()

See related question jQuery 1.9 .live() is not a function on how to migrate existing code. 参见相关问题jQuery 1.9 .live()不是有关如何迁移现有代码的函数

Tente usar .bind no lugar de .live Tente Usar .bind no lugar de .live

Try to use .bind instead of .live 尝试使用.bind而不是.live

对于使用> = v1.9的其他用户,请参见此处有关折旧的信息: jQuery 1.9 .live()不是函数

Find this funcion in wp-includes\\js\\thickbox\\thickbox.js and change the function: 在wp-includes \\ js \\ thickbox \\ thickbox.js中找到此功能并更改功能:

function tb_init(domChunk){
  jQuery(domChunk).live('click', tb_click);
}

Replacing the "live" method for "on", like this: 将“ live”方法替换为“ on”,如下所示:

function tb_init(domChunk){
    jQuery(domChunk).on('click',tb_click);
}

If you are using Nivo-Slider, the jquery.nivo.slider.js will need similar changes. 如果您使用的是Nivo-Slider,则jquery.nivo.slider.js将需要进行类似的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM