将 id 分配给 jquery 对话框按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4929394/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:11:46  来源:igfitidea点击:

assign id to jquery dialog button

jquerybuttondialog

提问by Hussein

How do i assign an an id to a jquery dialog button. I tried the following but it's not working

我如何为 jquery 对话框按钮分配一个 id。我尝试了以下但它不起作用

buttons: {
Ok: function() {
id="xyz",
...

回答by BerndB

The following (seemingly undocumented) works for me with jQuery 1.8.9:

以下(似乎没有记录)适用于 jQuery 1.8.9:

$("#dlg").dialog({
  buttons :  { 
     "MyButton" : {
         text: "My Button",
         id: "my-button-id",
         click: function(){
             alert("here");
         }   
      } 
   }
});

The button can be addressed via $("#my-button-id")

该按钮可以通过 $("#my-button-id") 寻址

回答by Andrei

This code from official site worked for me:

来自官方网站的这段代码对我有用:

$('#dialog').dialog({
    // properties ... 
    buttons: [{
        id:"btn-accept",
        text: "Accept",
        click: function() {
            $(this).dialog("close");
        }
    }, 
    {
        id:"btn-cancel",
        text: "Cancel",
        click: function() {
            $(this).dialog("close");
        }
    }]
});

回答by abayo oyewumi

@BerndB: Thanks it works perfectly and even is more extendable.

@BerndB:感谢它完美运行,甚至更具扩展性。

$('#loginlink').live('click',function(){
    DC = 'login_box';
    diaOpt = {
        autoOpen : true,
        width : 400,
        title : 'Login',
        buttons: {
            //valiudate login
            'Login' : {
                text : 'Login Now',
                id : 'validateForm',
                click : function(){
                }   
            }
        }
    }

    launchDialog(diaOpt, DC);
});

$('#validateForm').live('click', function(){
    alert('Hellop');
    $("#loginform").validate();
});

回答by naveen

Try this.

尝试这个。

buttons: {
    'MyButton': function() {
        //... configure the button's function
    }

And the id setter

和 id 设置器

$('button:contains(MyButton)').attr("id","xyz");  

回答by Rafay

$("#OK",{id:'xyz'});

hope that it helps

希望它有帮助