Zebra对话js - 尝试返回值false或true

时间:2018-03-06 15:20:59

标签: javascript boolean confirm zebra

我正在尝试从Zebra_Dialog框架返回一个值。我需要一个像true或false这样的值,以便将其作为输入发送,以便我可以更新我的商店卡。

问题是我能够使用confirm(它返回总是一个像true或false的值,但我不知道如何处理具有该结构的javascript框架。

到目前为止,我的代码如下:

确认():

$('#removebuttonstyle i').click(function() {
    console.log("you click!");
    var c = confirm("Are you sure that you want to continue?");
    return c;
});

zebra():

$('#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标题,我仍然会获得是或否,但我需要将值true或false重新赋值给变量。

1 个答案:

答案 0 :(得分:0)

这是我的解决方案:

$('#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;
        }
      });
    });