【问题标题】:How to pass the button name as variable in jquery dialogue box如何在 jquery 对话框中将按钮名称作为变量传递
【发布时间】:2015-02-20 11:22:07
【问题描述】:

我想调用对话框按钮的默认动作,所以请告诉我如何在对话框初始化中传递变量。这是我的尝试:

使用“是”按钮的默认功能调用对话框

$( "#confirmComplete" ).dialog( "option", "buttons:Yes");

$( "#confirmComplete" ).dialog({
     autoOpen: false,
     resizable: false,
     modal: true,
     async:false,
     position: 'top',
     buttons: {
         "Yes": function() {
                //SOME FUNCTIOANLITY
         }
     }
 })

【问题讨论】:

标签: javascript jquery jquery-ui jquery-ui-dialog


【解决方案1】:

将代码放在一个命名函数中,调用该函数:

function doYes() {
    // some functionality
}

$("#confirmComplete").dialog({
    autoOpen: false,
    resizable: false,
    modal: true,
    async: false,
    position: "top",
    buttons: {
        "Yes": doYes
    },
});

doYes(); // Call the default button action

【讨论】:

    【解决方案2】:

    你可以这样做:

    buttons: {
      "Yes": function() {
        $(this).dialog("close");
        return true;
      }
    }
    

    你也可以有一个关闭对话框的No按钮和return false;

    根据返回的true/false,您可以采取进一步的行动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多