用条件语句绑定模态窗口

Bind modal window with a conditional statment

本文关键字:模态 窗口 绑定 语句 条件      更新时间:2023-09-26

我有这个脚本的工作原理上的按钮点击,它弹出一个模态窗口与褪色的背景。这次我想实现的是将它包含在一个条件语句中。例如,如果var1= 2,则弹出模态窗口

// JavaScript Document

$(document).on("pagecreate", function () {
    $(".about").on("click", function () {
        // close button
        var closeBtn = $('<a href="#" data-rel="back" class="ui-btn-right ui-btn ui-btn-b ui-corner-all ui-btn-icon-notext ui-icon-delete ui-shadow">Close</a>');
        // text you get from Ajax
        var content = "<p> hello folks, good evening</p>";
        // Popup body - set width is optional - append button and Ajax msg
        var popup = $("<div/>", {
            "data-role": "popup"
        }).css({
            width: $(window).width() / 0 + "px",
            padding: 5 + "px"
        }).append(closeBtn).append(content);
        // Append it to active page
        $.mobile.pageContainer.append(popup);
        // Create it and add listener to delete it once it's closed
        // open it
        $("[data-role=popup]").popup({
            dismissible: false,
            history: false,
            theme: "b",
            /* or a */
            positionTo: "window",
            overlayTheme: "b",
            /* "b" is recommended for overlay */
            transition: "pop",
            beforeposition: function () {
                $.mobile.pageContainer.pagecontainer("getActivePage")
                    .addClass("blur-filter");
            },
            afterclose: function () {
                $(this).remove();
                $(".blur-filter").removeClass("blur-filter");
            },
            afteropen: function () {
                /* do something */
            }
        }).popup("open");
    });
});

像这样?:

$(".about").on("click", function () {
  if (var1!=2) return;
  ...(the rest of the function)