javascript - jQuery 函数不在条件循环中触发

标签 javascript jquery popup

scanStatus == 'limit' 时,centerPopup()loadPopup() 函数不会触发。

这些函数是从名为 js/count.js 的文件中调用的。该文件可用 here .

这些是我的函数,存储在 js/popup.js 中:

// Loading popup with jQuery magic!
function loadPopup() {
    // Loads popup only if it is disabled
    if (popupStatus == 0) {
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });

        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");

        popupStatus = 1;
    }
}

// Centering popup
function centerPopup() {
    // Request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();

    // Centering
    $("#popupContact").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });

    // Only need force for IE6
    $("#backgroundPopup").css({
        "height": windowHeight
    });
}

这两个文件都包含在 HTML 中,如下所示:

<script type="text/javascript">
    var uid = "rZCENk6w";
    var website = "http://www.engadget.com";
</script>

<script type="text/javascript" src="js/popup.js"></script>
<script type="text/javascript" src="js/count.js"></script>

预先感谢您的帮助。

最佳答案

基于代码found in the linked file (near the bottom) ,这些方法永远不会在文档准备就绪时调用,因为它们被注释掉了:

//if (scanStatus == 'limit') {
    //LOADING POPUP
    //Click the button event!
    //$("#button").click(function(){
        //centering with css
        //centerPopup();
        //load popup
        //loadPopup();
//});}

您需要取消注释它们才能相应地执行它们:

if (scanStatus == 'limit') {
    $("#button").click(function() {
        centerPopup();
        loadPopup();
    });
}

关于javascript - jQuery 函数不在条件循环中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8606509/

相关文章:

javascript - 为什么 axios 会导致 Access-Control-Allow-Origin 错误

javascript - ReactJs 带有 { hashHistory } 的不错的 URL

javascript - 修改获取到的JSON数据

带 svg 的 Jquery 选择器

javascript - 仅当再次单击时才关闭页面操作弹出窗口

javascript弹窗文件永远不会是 "ready"

javascript - Typescript:打开对象类型不起作用

javascript - 在 javascript/jquery 中,我如何将字符串(具有不一致的空格)解析为数组

javascript - 在弹出窗口中打开部分 View

javascript - 如果 "mousemove"和 "click"事件同时触发该怎么办?