【问题标题】:Change button in jQuery dialog boxjQuery 对话框中的更改按钮
【发布时间】:2009-08-29 07:21:06
【问题描述】:

我想知道,是否有适当的方法来删除标题栏中的默认关闭按钮并将其更改为其他,我想为其分配除关闭以外的其他功能。我设法更改了类,但尽管如此,关闭功能似乎覆盖了标题栏中的任何内容。

我当前用于更改课程的代码:

var closeButton = $("#dialog").parent().find('.ui-dialog-titlebar a');
closeButton.attr("class","ui-dialog-titlebar-lock");
closeButton.find("span").attr("class","ui-icon ui-icon-lock");

标题栏的HTML代码:

<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" unselectable="on" style="-moz-user-select: none;">
  <span id="ui-dialog-title-profile-dialog" class="ui-dialog-title" unselectable="on" style="-moz-user-select: none;">Edit My Profile</span>
    <a class="ui-dialog-titlebar-close ui-corner-all" href="#" role="button" unselectable="on" style="-moz-user-select: none;">
      <span class="ui-icon ui-icon-closethick" unselectable="on" style="-moz-user-select: none;">close</span>
    </a>
 </div>

由于之前的 javascript 代码,类被覆盖,但函数仍然存在。这是因为 jQuery 内部代码,我想,不是吗?有什么建议可以轻松克服吗?

【问题讨论】:

    标签: jquery function user-interface dialog


    【解决方案1】:

    我假设你的意思是关闭功能仍然存在。

    您可以做的是保留旧的点击事件,然后解除绑定,添加您自己的内部调用旧点击以实际关闭对话框。

    //persist old click
    var oldClickFn = closeButton.click;
    
    closeButton.unbind('click').click( function(){
        //functionality you want
    
        //call the persisted click
        oldClickFn && oldClickFn()
    });
    

    【讨论】:

    • 谢谢!这正是我想要的。
    【解决方案2】:

    以下应该有效:

    var dialog = // here open the dialog and assign it to the dialog variable
    dialog.parent(".ui-dialog").find(".ui-dialog-titlebar-close").unbind('click');        
    dialog.parent(".ui-dialog").find(".ui-dialog-titlebar-close").show();   
    dialog.parent(".ui-dialog").find(".ui-dialog-titlebar-close").bind('click', function() { showNoteDialogClose(null, null) });  
    
    
    function showNoteDialogClose(data, args)
    {
     /////////
    }   
    

    【讨论】:

      猜你喜欢
      • 2012-01-25
      • 1970-01-01
      • 1970-01-01
      • 2021-06-26
      • 2011-06-03
      • 1970-01-01
      • 2018-10-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多