Jquery弹出窗口不再工作

时间:2013-09-26 19:25:01

标签: javascript jquery css twitter-bootstrap popup

我有一个使用

工作的弹出脚本
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>.

我正在迁移到我使用的引导程序

<script src="//code.jquery.com/jquery.js"></script>.

删除第一个并使用第二个导致弹出窗口变为不可关闭。它打开但单击关闭按钮不起作用。如果我回到旧版本的jquery我的bootstrap下拉导航停止工作。我如何让这两者共存?

这是脚本:

<script type="text/javascript">
$(document).ready(function(){

//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="http://www.bakercommunications.com/images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({ 
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 

    return false;
});


//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  
}); //fade them both out

    return false;
});
});
</script>

我确实将弹出的CSS复制到bootstrap.css中。格式化很好,只是关闭功能似乎没有运行。这是我第一次使用这个网站,所以希望我已经足够清楚地解释了它。浪费了一天解决弹出问题,只是让它打破了顶级导航。

1 个答案:

答案 0 :(得分:1)

在jQuery 1.9中删除了

$.live,这可能是个问题。请尝试使用$.on代替:

$('a.close, #fade').on('click', function() {
相关问题