- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用DirtyForms并且该插件的基本功能正在运行。当用户尝试离开页面时,浏览器会抛出一个确认对话框。
我们使用 jQuery UI 的对话框进行模式确认,我试图让它与 DirtyForms 一起使用,它有一个直接引用 jQuery UI 对话框的示例。我直接使用他们页面中的示例来设置自定义对话框,但它没有使用 jQuery 对话框,它仍然使用浏览器的 native 对话框:
$.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;
}
}
打开插件调试后,我没有收到任何错误(或任何其他 JS 错误),但模式对话框不会触发,只有浏览器的 native 对话框。其他实现的 jQuery UI 对话框在同一页面上工作。我不确定我在这里可能会错过什么。任何帮助或见解将不胜感激。
最佳答案
最可能的问题是您的 HTML 标记中没有 ID 为 unsavedChanges
的 div
标记。因此,您应该添加 HTML...
<div id="unsavedChanges" style="display:none;" />
或 JavaScript 中的等效内容...
var $dlg = $('<div id="unsavedChanges" style="display:none;" />');
$('body').append($dlg);
如果这不是问题,我建议您编辑您的问题以包含 Minimal, Complete, and Verifiable Example ,通过发布整个 HTML 文档或使用诸如 JSFiddle 之类的服务.
NOTE: The custom dialog only works when a user clicks a hyperlink in the page. When the user interacts with the browser's navigation, the browser's dialog (if any) is shown. This is because there is no way to override the browser's default navigation behavior with a custom dialog.
In version 2.x it is now possible to customize the event binding, so you can add elements other than hyperlinks if clicking them navigates away from the current page.
关于javascript - 无法让自定义对话框与 DirtyForms 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15617322/
我正在使用DirtyForms并且该插件的基本功能正在运行。当用户尝试离开页面时,浏览器会抛出一个确认对话框。 我们使用 jQuery UI 的对话框进行模式确认,我试图让它与 DirtyForms
我对如何使用 jquery.dirtyforms 感到困惑. 我正在尝试创建一个带有文本框和提交按钮的简单表单。如果用户修改文本框并尝试刷新页面或在保存结果之前单击页面内的链接,Dirty Forms
在选项卡之间切换时,我尝试检查表单是否脏乱 - 如果表单脏乱,则显示警报。 我正在使用这个插件:https://github.com/snikch/jquery.dirtyforms 当尝试访问外部页
我正在使用 jQuery DirtyForms 插件来防止用户无意中离开页面而不保存。我在使用对话框时遇到了一些麻烦。我有两个按钮:取消和不保存。 “取消”操作正常工作:对话框关闭并且未加载新页面。但
我们使用 JQuery dirtyform 插件在用户更改表单数据并尝试离开页面时向用户显示警告,并且效果良好。 我想做的另一件事是在页面首次加载时强制表单变脏。我不知道如何做到这一点 - 我尝试使用
site 中的示例通常假设使用jquery对话框,例如facebox或jquery-ui。是否可以使用 native 浏览器的confirm()作为对话框?如果是这样,有没有办法绑定(bind)确定和
我正在使用 DirtyForms和 $.blockUI插件,后者在单击链接时更改页面(在我的应用程序中,某些页面需要几秒钟才能加载并且视觉反馈很好)。 当我更改字段内容然后单击任何链接时,会触发 Di
我是一名优秀的程序员,十分优秀!