我使用this来测试表单是否脏。 默认为标准浏览器确认,询问您是否确定要从此页面导航。在jQuery的dirtyforms网站上有一个部分,说你可以使用jquery ui模式表单。jquery脏记录,想要jquery ui模式
所以,我想,像这样添加一个部分(一个div):
<div id="unsavedChanges" title="Save Changes?">
<p>You've made changes to this page. Do you want to leave this page without saving?</p>
</div>
然后我说看起来像什么他们的代码:
$.DirtyForms.dialog = {
selector: '#unsavedChanges',
fire: function(message, dlgTitle) {
$('#unsavedChanges').dialog({ title: dlgTitle, width: 350, modal: true });
$('#unsavedChanges').html(message);
},
bind: function() {
$('#unsavedChanges').dialog('option', 'buttons',
[
{
text: "Stay Here",
click: function(e) {
$.DirtyForms.choiceContinue = false;
$(this).dialog('close');
}
},
{
text: "Leave This Page",
click: function(e) {
$.DirtyForms.choiceContinue = true;
$(this).dialog('close');
}
}
]
).bind('dialogclose', function(e) {
// Execute the choice after the modal dialog closes
$.DirtyForms.choiceCommit(e);
});
},
refire: function(content) {
return false;
},
stash: function() {
return false;
}
};
虽然我不知道他们想要我(我最初把它放在document.ready
之外,然而,在运行这个并对我的表单进行更改并导航之后,我发现它仍然使用浏览器确认而不是jquery ui对话框。 ?
hmmmm。通过阅读文档,我明白这是从他引用jquery 1.4.2和1.7.2开始就有点古怪了。从那以后,jquery和jquery ui都开始有了。任何人,你可以发布一个这样的小提琴,所以我们可以玩它使用jQuery和你使用的jQuery UI的版本? – Rooster
这看起来像一个更新的等效:http://plugins.jquery.com/are-you-sure/ – Anthony
是否有浏览器相关的安全问题,实际上需要您使用浏览器确认对话框?我认为除了通过onbeforeunload事件(它只能返回一个字符串)之外,浏览器无法通过JavaScript进行浏览。 –