如何删除jQueryUI创建的对话框上的关闭按钮(右上角的X)?
当前回答
document.querySelector('.ui-dialog-titlebar-close').style.display = 'none'
其他回答
您也可以删除标题行:
<div data role=“header”></分区>
其移除关闭按钮。
以上这些都不起作用。真正有效的解决方案是:
$(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
})
请检查它是否适合您。
隐藏按钮的最佳方法是使用其数据图标属性对其进行过滤:
$('#dialog-id [data-icon="delete"]').hide();
如官方页面所示,David建议:
创建样式:
.no-close .ui-dialog-titlebar-close {
display: none;
}
然后,您可以简单地将no close类添加到任何对话框中,以隐藏其关闭按钮:
$( "#dialog" ).dialog({
dialogClass: "no-close",
buttons: [{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
}]
});
这是针对jQuery UI 1.12的。我为“classes”选项添加了以下配置设置
classes: {
'ui-dialog-titlebar-close': 'hidden',
},
整个对话框初始化如下所示:
ConfirmarSiNo(titulo, texto, idPadre, fnCerrar) {
const DATA_RETORNO = 'retval';
$('confirmar-si-no').dialog({
title: titulo,
modal: true,
classes: {
'ui-dialog-titlebar-close': 'hidden',
},
appendTo: `#${idPadre}`,
open: function fnOpen() { $(this).text(texto); },
close: function fnClose() {
let eligioSi = $(this).data(DATA_RETORNO) == true;
setTimeout(function () { fnCerrar(eligioSi); }, 30);
},
buttons: {
'Si, por favor': function si() { $(this).data(DATA_RETORNO, true); $(this).dialog("close"); },
'No, gracias': function no() { $(this).data(DATA_RETORNO, false); $(this).dialog("close"); }
}
});
}
我使用以下脚本调用来显示它:
ConfirmarSiNo('Titulo',
'¿Desea actualizar?',
idModalPadre,
(eligioSi) => {
if (eligioSi) {
this.$tarifa.val(tarifa.tarifa);
this.__ActualizarTarifa(tarifa);
}
});
在Html主体中,我有以下包含对话框的div:
<div class="modal" id="confirmar-si-no" title="" aria-labelledby="confirmacion-label">
mensaje
</div>
最终结果是:
函数“ConfirmarSiNo”基于帖子中的“Whome”答案。如何在Jquery UI对话框中实现“确认”对话框?
推荐文章
- 使伸缩项目正确浮动
- 可以在setInterval()内部调用clearInterval()吗?
- 无法读取未定义的属性“msie”- jQuery工具
- 如何取消最大高度?
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何选择在最后一个子元素之前的元素?
- 如何触发自动填充在谷歌Chrome?
- jQuery:执行同步AJAX请求
- CSS变换,锯齿边缘在铬
- 创建圈div比使用图像更容易的方法?
- 强迫孩子服从父母的弯曲边界在CSS
- jQuery表格排序
- 如何禁用文本选择使用jQuery?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?