javascript - Jquery 弹出窗口不再工作

标签 javascript jquery css twitter-bootstrap popup

<分区>

我有一个有效的弹出脚本,使用

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>.

我正在迁移到让我使用的 bootstrap

<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 中。格式很好,只是关闭功能似乎没有运行。这是我第一次使用这个网站,所以希望我已经解释清楚了。浪费了一天的时间来解决弹出窗口问题,却让它破坏了顶部导航。

最佳答案

$.live在 jQuery 1.9 中被删除,这可能是问题所在。尝试使用 $.on相反:

$('a.close, #fade').on('click', function() {

关于javascript - Jquery 弹出窗口不再工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19036922/

相关文章:

jquery - 从一组图像到另一组图像的滑动过渡

javascript - Chrome 扩展程序臃肿的背景页面

javascript - 如何获取NodeList中的Node位置?

javascript - 我想在模态窗口中显示 PDF ajax 响应

jquery - 如何在表格列中居中按钮/文本?

html - 内部有图像的 w3-cell 元素不会调整到等高

html - @font-face - 奇怪的 CSS 字体请求 URL

javascript - 如何在 angularjs 中显示 json 的值

javascript - Asp.Net Repeater - 通过 Javascript 调用 ItemCommand 事件

javascript - 每行文本下方有线条的文本区域