有没有可能打开一个jQuery UI对话框没有标题栏?
当前回答
这招对我很管用:
$("#dialog").dialog({
create: function (event, ui) {
$(".ui-widget-header").hide();
},
其他回答
我想出了一个动态删除标题栏的解决方案。
$("#example").dialog(dialogOpts);
// remove the title bar
$(".ui-dialog-titlebar").hide();
这将在对话框渲染后删除所有带有'ui-dialog-titlebar'类的元素。
我喜欢重写jQuery小部件。
(function ($) {
$.widget("sauti.dialog", $.ui.dialog, {
options: {
headerVisible: false
},
_create: function () {
// ready to generate button
this._super("_create"); // for 18 would be $.Widget.prototype._create.call(this);
// decide if header is visible
if(this.options.headerVisible == false)
this.uiDialogTitlebar.hide();
},
_setOption: function (key, value) {
this._super(key, value); // for 1.8 would be $.Widget.prototype._setOption.apply( this, arguments );
if (key === "headerVisible") {
if (key == false)
this.uiDialogTitlebar.hide();
else
this.uiDialogTitlebar.show();
return;
}
}
});
})(jQuery);
你现在可以设置是否显示标题栏
$('#mydialog').dialog({
headerVisible: false // or true
});
这是最简单的方法,它只会删除一个特定对话框中的标题栏;
$('.dialog_selector').find('.ui-dialog-titlebar').hide();
实际上还有另一种方法,直接使用对话框小部件:
您可以这样获得对话框小部件
$("#example").dialog(dialogOpts);
$dlgWidget = $('#example').dialog('widget');
然后做
$dlgWidget.find(".ui-dialog-titlebar").hide();
仅在该对话框中隐藏标题栏
并且在一行代码中(我喜欢链接):
$('#example').dialog('widget').find(".ui-dialog-titlebar").hide();
不需要在对话框中添加一个额外的类,直接就可以了。对我来说没问题。
我发现使用open事件并从那里隐藏标题栏更有效,更可读。我不喜欢使用页全局类名搜索。
open: function() { $(this).closest(".ui-dialog").find(".ui-dialog-titlebar:first").hide(); }
简单。
推荐文章
- jQuery等价于JavaScript的addEventListener方法
- jQuery需要避免的陷阱
- 用jQuery切换DIV背景图像
- 如何让一个按钮将我的页面重定向到另一个页面?
- 如何让元素被点击(对于整个文档)?
- 使用jQuery改变输入字段的类型
- 使用jQuery以像素为整数填充或边距值
- 检查是否选择了jQuery选项,如果没有选择默认值
- 将Dropzone.js与其他字段集成到现有的HTML表单中
- 使用jQuery滚动到一个div
- 在JS/jQuery中触发按键/按键/按键事件?
- 如何每5秒重新加载页面?
- getJSON调用中的错误处理
- 如何用jquery或javascript排序对象数组
- 使用jQuery切换输入禁用属性