$('#yourdiv'). // Get your box ...dialog(). // ... and turn it into dialog (autoOpen: false also works)prev('.ui-dialog-titlebar'). // Get title bar,...find('a'). // ... then get the X close button ...hide(); // ... and hide it
$(function(){//this is your dialog:$('#mydiv').dialog({// Step 1. Add an extra class to our dialog to address the dialog directly. Make sure that this class is not used anywhere else:dialogClass: 'my-extra-class'})// Step 2. Hide the close 'X' button on the dialog that you marked with your extra class$('.my-extra-class').find('.ui-dialog-titlebar-close').css('display','none');// Step 3. Enjoy your dialog without the 'X' link})
$("#div2").dialog({ // call .dialog method to create the dialog markupautoOpen: false});$("#div2").dialog("widget") // get the dialog widget element.find(".ui-dialog-titlebar-close") // find the close button for this dialog.hide(); // hide it
$("#div3").dialog({open: function() { // open event handler$(this) // the element being dialogged.parent() // get the dialog widget element.find(".ui-dialog-titlebar-close") // find the close button for this dialog.hide(); // hide it}});
仅供参考,对话框标记看起来像这样:
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable"><!-- ^--- this is the dialog widget --><div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix"><span class="ui-dialog-title" id="ui-dialog-title-dialog">Dialog title</span><a class="ui-dialog-titlebar-close ui-corner-all" href="#"><span class="ui-icon ui-icon-closethick">close</span></a></div><div id="div2" style="height: 200px; min-height: 200px; width: auto;" class="ui-dialog-content ui-widget-content"><!-- ^--- this is the element upon which .dialog() was called --></div></div>
$('#dialog-modal').dialog({//To hide the Close 'X' button"closeX": false,//To disable closing the pop up on escape"closeOnEscape": false,//To allow background scrolling"allowScrolling": true})//To remove the whole title bar.siblings('.ui-dialog-titlebar').remove();
(function ($) {$.fn.dialogNoClose = function () {return this.each(function () {// hide the close button and prevent ESC key from closing$(this).closest(".ui-dialog").find(".ui-dialog-titlebar-close").hide();$(this).dialog("option", "closeOnEscape", false);});};})(jQuery)
使用示例:
$("#dialog").dialog({ /* lots of options */ }).dialogNoClose();