【问题标题】:Zebra dialogue js - trying to return a value false or true斑马对话js - 试图返回一个值假或真
【发布时间】:2018-08-14 12:19:50
【问题描述】:

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

问题是我可以通过确认来做到这一点(它总是返回一个像 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;
  });

正如您可以想象的那样,斑马方法行不通。有什么帮助吗?是谁干的?

更新:我实际上取得了一些进展,所以最后一步是将值重新分配为真或假:

$('#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 给变量。

【问题讨论】:

    标签: javascript boolean confirm zebra


    【解决方案1】:

    这是我的解决方案:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      相关资源
      最近更新 更多