【问题标题】:How can I change the text of a DIALOG button after initialize?初始化后如何更改 DIALOG 按钮的文本?
【发布时间】:2014-11-04 13:56:06
【问题描述】:

我写了一个对话框定义,但按钮的名称取决于情况。 当我打开对话框时,我想设置按钮名称。 我找不到解决方案,如何在定义对话框按钮后重命名它。 这是我的对话代码:

     $( "#neueFrage" ).dialog({
     resizable: false,
     autoOpen: false,
     height: 900,
     width: 1100,
     modal: true,
     closeOnEscape: false,
       open: function(event, ui) { $(".ui-dialog-titlebar-close").hide()},
       buttons     : [{
                          text    : 'SAVE',
                          class : 'dialogbutton',
                          click    : function() {}
                      },
                      {
                          text    : 'CANCEL',
                          class : 'dialogbutton',
                          click    : function() {
                          }
                      }
                  ]    
     });

我用这个小代码示例调用对话框。 如果“是”,一切正常,但如果不是,我想将按钮重命名为“重做”。

if ($(this).text()=="Yes") {
    $( "#neueFrage" ).dialog( "open" );
} else {
    //Rename the button 'SAVE' to 'REDO' before open dialog
    $( "#neueFrage" ).dialog( "open" );
}

如何在else中更改按钮的名称?

【问题讨论】:

    标签: javascript jquery button dialog uibutton


    【解决方案1】:

    试试这个:

    buttons     : [
                              {
    
                                  text    : 'SAVE',
                                  class : 'dialogbutton',
                                  click    : function() {},
                                  id:"savebtn"
    
                              },
                              {
                                  text    : 'CANCEL',
                                  class : 'dialogbutton',
                                  click    : function() {
    
    
                                  },
                                  id:"cancelbtn"
                              }
                          ]    
             });
    
    if($(this).text()=="Yes"){
      $( "#neueFrage" ).dialog( "open" );    
    }else{
    $("#savebtn").find("span").text("whatever")
     $( "#neueFrage" ).dialog( "open" );
    }
    

    【讨论】:

    • 谢谢,这有帮助。不知何故,我没有意识到,您可以为这些按钮提供 ID。
    猜你喜欢
    • 2015-04-16
    • 2019-05-23
    • 2011-01-04
    • 2012-01-29
    • 1970-01-01
    • 2011-01-17
    • 2019-01-24
    • 1970-01-01
    • 2016-06-18
    相关资源
    最近更新 更多