- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试使用 alertify.js
作为我所有确认脚本的确认对话框。但它不像常规 JS confirm
那样工作。在下面的代码中,我从未得到 return true
function aConf ( mes ) {
alertify.confirm( mes, function (e) {
return e;
});
}
<a href="#" onclick="if(aConf(\'Are you sure you wish to remove this?\')) { function(); } return false;">Delete</a>
当然,如果我用 JS 的 confirm
替换 aConf
它就可以了。那么,为什么 alertify
没有将结果发回给我?
最佳答案
因为confirm是一个阻塞函数(javascript在返回true/false之前不会运行),而alertify是非阻塞的(JS一直在执行)。 Alertify 不会立即返回 true/false,相反,它可能会立即返回 undefined,然后在用户单击 OK 或 Cancel 后调用回调函数。该回调函数的返回值在您的示例中没有影响,因为 onclick 代码已经完成运行(因为它是非阻塞的)。
假设您使用的是:https://github.com/fabien-d/alertify.js/
这是它实际使用回调函数而不是返回值的方式:
alertify.confirm( message, function (e) {
if (e) {
//after clicking OK
} else {
//after clicking Cancel
}
});
对于您的代码示例,您可以尝试如下操作:
function performDelete ( a_element ) {
// perform your delete here
// a_element is the <a> tag that was clicked
}
function confirmAction ( a_element, message, action ) {
alertify.confirm(message, function(e) {
if (e) {
// a_element is the <a> tag that was clicked
if (action) {
action(a_element);
}
}
});
}
<a href="#" onclick="confirmAction(this, 'Are you sure you wish to remove this?', performDelete); return false;">Delete</a>
编辑:更新为通用确认对话框,如果用户单击“确定”,则调用回调函数。
关于从确认返回的 Javascript Alertify,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14408627/
我正在使用 alertify.error 来显示错误消息。我想知道是否有任何方法可以更改显示在里面的文本的字体颜色? 最佳答案 好吧,正如我所见,它使用这段代码来更改字体颜色和整体字体样式: .ale
我正在为我的对话框使用 Alertify Jquery 插件。问题是,一次确认后一次确认似乎不起作用: // confirm dialog function go(){ alertify.co
我决定使用 Alertify 来修改和设计我的代码。我的旧代码: $('.ask').click(function(){ var answer = confirm('translate('D
我是alertify.js的新手。我想做的是,当用户点击链接时,浏览器应该显示确认框。如果用户单击 则转到下一页。如果用户单击“取消”,则留在同一页面上。是否可以使用alertify.js来做到这一点
我刚刚写了一些代码,遇到了这样的问题: alertify.dialog("confirm").set( { 'labels': { ok: 'Personal',
我有一个按钮,单击该按钮后,我将在 Bootstrap 模型中显示一个表单。我想要实现的是在表单提交时显示确认框。一切正常,但确认信息出现在引导模型的后台。 HTML Notify Cust
我有这样的 HTML 行 (new) save -
所以我有这些代码行: $('td').click(function (e) { var test = "...."; var test2 = "...."; var test3
我正在尝试使用 alertify.js 作为我所有确认脚本的确认对话框。但它不像常规 JS confirm 那样工作。在下面的代码中,我从未得到 return true function aConf
我的页面中有一个表单可以自行提交。在 PHP 部分我检查 if($_SERVER['REQUEST_METHOD'] == 'POST') 然后我运行一些东西。我正在尝试使用 Alertify 显示警
您好,我正在尝试将alertify.js 作为警报弹出窗口包含在我的网页上,但我不确定为什么它没有显示。我已经下载了alertify 的库和源代码,但我不确定我是否正确使用它。任何建议都会有很大帮助。
使用alertify - 版本0.3.11,我能够获取用户输入详细信息并能够在提示对话框中显示它。但我有多种值(value)观。用户输入、下拉值、日期选择等 var totalResources =
$("#btn_submit").click(function(){ alertify.prompt("Please enter note/remarks for this Form:", f
我正在使用 Alertify 库在我的 javascript 中创建一个对话框, alertify.myAlert || alertify.dialog('myAlert',function fact
我在使用 alertify JS confirm 时遇到了问题。当我单击该按钮时,不会出现 alertify 确认,但会立即重定向到该链接。以下脚本链接按钮和 alertify 确认脚本。 funct
有没有办法让 Alertify Js 插件的对话窗口居中? http://alertifyjs.com 我看到有个属性叫position,但是不支持center position。 谢谢大家 最佳答案
我正在尝试将以下老派代码片段转换为 alertify.js 0.3.8: window.doPrompt = function() { var str; do str = prompt("En
我正在使用 Alertify JQuery 插件,用于显示 alert,confirm, dialog 框。 确认时遇到问题,单击“确定”或“取消”时无法正常工作 Sample JS FIDDLE J
我正在尝试使用alertifyjs(https://alertifyjs.org/)库。 在代码预览网站(例如codepen)中或在stackoverflow上测试警报时,警报将按预期方式工作。 但是
我正在开始使用 jquery 插件,并且决定尝试一下 Alertify。我访问了网页: http://fabien-d.github.io/alertify.js/ 它告诉我使用 Bower 包管理进
我是一名优秀的程序员,十分优秀!