1

在 jQuery Mobile 项目中,有一个对话框(不是弹出窗口),其中包含一些字段和两个按钮,样式如下:

        <a data-role="button" data-inline="true" data-transition="none" href="#"
            data-icon="check" data-iconpos="left" id="saveEdit">Save
        </a>
        <a data-role="button" data-inline="true" data-transition="none" href="#"
            data-icon="delete" data-iconpos="left" id="closeEdit">Cancel
        </a>

单击其中一个时,单击事件处理程序将关闭对话框:

$(document).on("vclick", "#saveEdit", function () {

    LoginCookie(EditDoc, "Y");
    $('.ui-dialog').dialog('close');
});

但是,当这种情况发生时,还会在对话框“后面”的任何内容上触发 click 事件,几乎就像您正在“通过”对话框按钮点击一样,即使它仍然在按钮上触发 click 事件。有没有办法防止这种行为?

4

2 回答 2

1

I'm finding the only thing that works for me is to make the modal blocking, particularly for laggy interfaces, like just about all older Android versions. You're intending for the user to tap on elements within the modal to close it. Here's a pattern as part of your handler:

window.setTimeout(function(){
        $(myModal).on({
            popupbeforeposition: function () { //make the popup blocking - no click outside to close
                $('.ui-popup-screen').off();
            }
        }).popup("open");
    }, 500);

Of course, this means the user can't just tap outside the modal to close it. But if you have a lot of form or other interactive elements on the page, I think this is a pretty crucial adjustment for usability.

于 2013-05-22T00:22:12.187 回答
1

这似乎已经解决了它:

 $(document).on("vclick", "#saveEdit", function (e) {


            e.preventDefault();


            LoginCookie(EditDoc, "Y");
            $('.ui-dialog').dialog('close');
        });
于 2012-11-01T14:03:29.977 回答