jQuery.simplemodal-1.3.5 插件:类选择器神秘消失

发布于 2024-09-09 11:52:30 字数 3649 浏览 5 评论 0原文

我遇到了以下问题:

在模式处于活动状态时(以编程方式)添加到模式弹出窗口内的元素的类定义在模型关闭后不会保留。这与通过标准 jQuery 方法“隐藏”和“显示”元素后类定义保留在元素上的情况形成对比。

为了说明问题,请在下面找到一个测试页。

有什么解释吗?

预先感谢,

-Itai

单击“jQuery Show Modal”

单击“添加类”

单击“jQuery Hide Modal”

单击“jQuery Show Modal”

单击“显示类”(您将看到“aClass anotherClass”)

单击“jQuery Hide Modal”

单击SimpleModal 打开

单击“Show Class”(您将看到“aClass anotherClass”)

单击 SimpleModal 关闭

单击“jQuery Show Modal”

单击“Remove Class”

单击“Show Class”(您将仅看到“aClass”)

单击“jQuery Hide Modal”

单击 SimpleModal 打开

单击“添加类”

单击“显示类”(您将看到“aClass anotherClass”)

单击 SimpleModal 关闭

单击 SimpleModal

打开 单击“显示类”(您将看到“aClass”) <-- 问题(anotherClass 不存在)保留)

// Test.html 将 $link$ 替换为

测试

<script type="text/javascript">
jQuery(function($) {

    $("#btnjQueryShow").click(function(){
        $('#test-frame').show();
    });

    $("#btnQueryHide").click(function(){
        $('#test-frame').hide();
    });

    $("#btnAddClass").click(function(){
        $('#divClassHolder').addClass("anotherClass");
    });

    $("#btnRemoveClass").click(function(){
        $('#divClassHolder').removeClass("anotherClass");
    });

    $("#btnShowClass").click(function(){    
        var classNames = "";
        var classList = $('#divClassHolder').attr('class').split(' '); 
            $.each( classList, function(index, item){ 
                classNames += item + " ";
            }); 

        alert(classNames);
    });
});

</script>

<!-- DOM Show / Hide-->
<div>
    <input id="btnjQueryShow" type="button" value="jQuery Show Modal" />
    <input id="btnQueryHide" type="button" value="jQuery Hide Modal" />
</div>

<br/>
<br/>
<br/>

$link$"#" id="popup-opener">SimpleModal Open</a>
<br>
<br>
<div id="test-frame" style="display:none; width:500px; background-color:white; border: solid 1px red">
    $link$"#" id="popup-closer" class="simplemodal-close" style="float:right;">SimpleModal Close</a><br>
    <div id="divClassHolder" class="aClass">
        <input id="btnAddClass"    type="button"  value="Add Class" />
        <input id="btnRemoveClass" type="button"  value="Remove Class" />
        <input id="btnShowClass"   type="button"  value="Show Class" />
    </div>
</div>

// popup.js

jQuery(function($) { var frm = { 消息:空, 初始化:函数(){ $('#popup-opener').click(function(e) { e.preventDefault();

            $('#test-frame').modal(
 {
     overlayId: 'form-overlay',
     overlayCss: { backgroundColor: "#4178F0" },
     containerId: 'form-container',
     onOpen: frm.open,
     onShow: frm.show,
     close: false,
     minHeight: 590,
     minWidth: 635,
     position: ["5%", ],
  onClose: function(dialog) {
   $.modal.close();
  }
 });
        });
    },
    open: function(dialog) {

        // open handler
        dialog.overlay.show();

        dialog.container.show();

        dialog.data.show();            
        // file styles are not available in hidden divs!!
    },
    show: function(dialog) {

    },
    close: function(dialog) {

    },
    error: function(xhr) {
        // error handler
    },
    validate: function() {
        // validate handler
    },
    showError: function() {
        // error handler
    }
};

frm.init();

});

I have encountered the following issue:

A class definition added (programmatically) to an element inside the modal popup while the modal is active, is not retained after the model is closed. This is in contrast to a situation where the class definition is retained on the element after “hiding” and “showing” it via standard jQuery methods.

To illustrate the problem, please find below a test page.

Any explanation?

Thanks in advance,

-Itai

Click “jQuery Show Modal”

Click “Add Class”

Click “jQuery Hide Modal”

Click “jQuery Show Modal”

Click “Show Class” (You will see “aClass anotherClass”)

Click “jQuery Hide Modal”

Click SimpleModal Open

Click “Show Class” (You will see “aClass anotherClass”)

Click SimpleModal Close

Click “jQuery Show Modal”

Click “Remove Class”

Click “Show Class” (You will see only “aClass”)

Click “jQuery Hide Modal”

Click SimpleModal Open

Click “Add Class”

Click “Show Class” (You will see “aClass anotherClass”)

Click SimpleModal Close

Click SimpleModal Open

Click “Show Class” (You will see “aClass”) <-- Problem (anotherClass was not retained)

// Test.html
replace $link$ with

Test

<script type="text/javascript">
jQuery(function($) {

    $("#btnjQueryShow").click(function(){
        $('#test-frame').show();
    });

    $("#btnQueryHide").click(function(){
        $('#test-frame').hide();
    });

    $("#btnAddClass").click(function(){
        $('#divClassHolder').addClass("anotherClass");
    });

    $("#btnRemoveClass").click(function(){
        $('#divClassHolder').removeClass("anotherClass");
    });

    $("#btnShowClass").click(function(){    
        var classNames = "";
        var classList = $('#divClassHolder').attr('class').split(' '); 
            $.each( classList, function(index, item){ 
                classNames += item + " ";
            }); 

        alert(classNames);
    });
});

</script>

<!-- DOM Show / Hide-->
<div>
    <input id="btnjQueryShow" type="button" value="jQuery Show Modal" />
    <input id="btnQueryHide" type="button" value="jQuery Hide Modal" />
</div>

<br/>
<br/>
<br/>

$link$"#" id="popup-opener">SimpleModal Open</a>
<br>
<br>
<div id="test-frame" style="display:none; width:500px; background-color:white; border: solid 1px red">
    $link$"#" id="popup-closer" class="simplemodal-close" style="float:right;">SimpleModal Close</a><br>
    <div id="divClassHolder" class="aClass">
        <input id="btnAddClass"    type="button"  value="Add Class" />
        <input id="btnRemoveClass" type="button"  value="Remove Class" />
        <input id="btnShowClass"   type="button"  value="Show Class" />
    </div>
</div>

// popup.js

jQuery(function($) {
var frm = {
message: null,
init: function() {
$('#popup-opener').click(function(e) {
e.preventDefault();

            $('#test-frame').modal(
 {
     overlayId: 'form-overlay',
     overlayCss: { backgroundColor: "#4178F0" },
     containerId: 'form-container',
     onOpen: frm.open,
     onShow: frm.show,
     close: false,
     minHeight: 590,
     minWidth: 635,
     position: ["5%", ],
  onClose: function(dialog) {
   $.modal.close();
  }
 });
        });
    },
    open: function(dialog) {

        // open handler
        dialog.overlay.show();

        dialog.container.show();

        dialog.data.show();            
        // file styles are not available in hidden divs!!
    },
    show: function(dialog) {

    },
    close: function(dialog) {

    },
    error: function(xhr) {
        // error handler
    },
    validate: function() {
        // validate handler
    },
    showError: function() {
        // error handler
    }
};

frm.init();

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早乙女 2024-09-16 11:52:30

默认情况下,SimpleModal 克隆对话框中使用的内容。您有几种不同的选择可以尝试。

1) 使用 persist 选项:

$('#foo').modal({persist:true});

2) 在 onShow 回调中添加类:

$('#foo').modal({
    onShow: function (dialog) {
        var classList = $('#divClassHolder', dialog.data[0]) ...
    }
});

另外,只是想提一下,在您提供的代码中,使用 onClose 回调并调用 $.modal。 close(); 不是必需的。当对话框关闭时,它将自动执行该步骤。

希望有帮助。

-埃里克

By default, SimpleModal clones the content being used in the dialog. You have a few different options you can try.

1) Use the persist option:

$('#foo').modal({persist:true});

2) Add the class in the onShow callback:

$('#foo').modal({
    onShow: function (dialog) {
        var classList = $('#divClassHolder', dialog.data[0]) ...
    }
});

Also, just wanted to mention that in the code you provided, using the onClose callback and calling $.modal.close(); is not necessary. When the dialog closes, it will automatically perform that step.

Hope that helps.

-Eric

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文