使用JQuery DirtyForms插件的示例

Ste*_*rno 3 jquery jquery-plugins jquery-dirtyforms

我正在使用jQuery DirtyForms插件来防止用户无意中离开页面而不保存.我在对话框中遇到了一些麻烦.我有两个按钮:取消和不保存.

"取消"操作正常工作:对话框关闭,未加载新页面.但是,"不保存"操作无效.应该加载新页面,但它没有发生.

我一定错过了一些明显的东西.谁能看到我做错了什么?

<script type="text/javascript">

    $(document).ready(function(){
            $('form').dirtyForms();
    });

    $('a').click(function(event){
            event.preventDefault();
            var targetUrl = $(this).attr("href");

            if($.DirtyForms.isDirty()){
                    $("#dialog-savechanges").dialog({
                            height: 250,
                            width: 500,
                            modal: true,
                            buttons: {
                                    Cancel: function() {
                                            $( this ).dialog( "close" );
                                            $.DirtyForms.choiceContinue = false;
                                            $.DirtyForms.choiceCommit(event);
                                    },
                                    "Don't Save": function() {
                                            $( this ).dialog( "close" );
                                            $.DirtyForms.choiceContinue = true;
                                            $.DirtyForms.choiceCommit(event);
                                    }
                            }
                    });
            }
    });

</script>

<div id="dialog-savechanges" title="Save Changes?">
    <p>You've made changes to this page. Do you want to leave this page without saving?</p>
</div>
Run Code Online (Sandbox Code Playgroud)

谢谢!

史蒂夫

Ste*_*rno 7

好吧,我知道这是显而易见的......希望这会有助于其他人.

问题是preventDefault函数:

event.preventDefault();
Run Code Online (Sandbox Code Playgroud)

删除后,对话框按预期运行.