Zebra 对话 js - 试图 return 值 false 或 true
Zebra dialogue js - trying to return a value false or true
我正在尝试 return 来自 Zebra_Dialog 框架的值。我需要一个像 true 或 false 这样的值才能将其作为输入发送,这样我就可以更新我的商店卡片。
问题是我可以通过确认来做到这一点(return 总是像 true 或 false 这样的值,但我不知道如何使用 javascript具有该结构的框架。
到目前为止我的代码如下:
确认():
$('#removebuttonstyle i').click(function() {
console.log("you click!");
var c = confirm("Are you sure that you want to continue?");
return c;
});
斑马():
$('#removebuttonstyle i').on('click', function(e) {
console.log("you click!");
e.preventDefault();
var t = $.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
type: 'question',
title: 'Custom buttons',
buttons: ['Yes', 'No'],
onClose: function(buttons) {
if (buttons=='Yes') {
return true;
} else {
return false;
}
}
});
return buttons;
});
就像您想象的那样,斑马线方法行不通。有什么帮助吗?是谁干的?
更新:我实际上取得了一些进展,所以最后一步是将值重新分配为 true 或 false:
$('#removebuttonstyle i').on('click', function(e) {
console.log("you click!");
e.preventDefault();
var t = $.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
type: 'question',
title: 'Custom buttons',
buttons: [
{caption: 'Yes'},
{caption: 'No'}
],
onClose: function(caption) {
caption == 'Yes' ? true : false;
console.log(caption);
}
});
});
如果我console.log caption我仍然得到yes or not,但是我需要重新赋值true或false给变量。
这是我的解决方案:
$('#removebuttonstyle i').on('click', function(e) {
e.preventDefault();
var t = $.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
type: 'question',
title: 'Custom buttons',
buttons: [
{caption: 'Yes'},
{caption: 'No'}
],
onClose: function(caption) {
if (caption == 'Yes') {
$("#removebuttonstyle i").unbind('click').click()
} else {
caption = false;
}
return caption;
}
});
});
我正在尝试 return 来自 Zebra_Dialog 框架的值。我需要一个像 true 或 false 这样的值才能将其作为输入发送,这样我就可以更新我的商店卡片。
问题是我可以通过确认来做到这一点(return 总是像 true 或 false 这样的值,但我不知道如何使用 javascript具有该结构的框架。
到目前为止我的代码如下:
确认():
$('#removebuttonstyle i').click(function() {
console.log("you click!");
var c = confirm("Are you sure that you want to continue?");
return c;
});
斑马():
$('#removebuttonstyle i').on('click', function(e) {
console.log("you click!");
e.preventDefault();
var t = $.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
type: 'question',
title: 'Custom buttons',
buttons: ['Yes', 'No'],
onClose: function(buttons) {
if (buttons=='Yes') {
return true;
} else {
return false;
}
}
});
return buttons;
});
就像您想象的那样,斑马线方法行不通。有什么帮助吗?是谁干的?
更新:我实际上取得了一些进展,所以最后一步是将值重新分配为 true 或 false:
$('#removebuttonstyle i').on('click', function(e) {
console.log("you click!");
e.preventDefault();
var t = $.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
type: 'question',
title: 'Custom buttons',
buttons: [
{caption: 'Yes'},
{caption: 'No'}
],
onClose: function(caption) {
caption == 'Yes' ? true : false;
console.log(caption);
}
});
});
如果我console.log caption我仍然得到yes or not,但是我需要重新赋值true或false给变量。
这是我的解决方案:
$('#removebuttonstyle i').on('click', function(e) {
e.preventDefault();
var t = $.Zebra_Dialog('<strong>Zebra_Dialog</strong>, a small, compact and highly configurable dialog box plugin for jQuery', {
type: 'question',
title: 'Custom buttons',
buttons: [
{caption: 'Yes'},
{caption: 'No'}
],
onClose: function(caption) {
if (caption == 'Yes') {
$("#removebuttonstyle i").unbind('click').click()
} else {
caption = false;
}
return caption;
}
});
});