有没有可能打开一个jQuery UI对话框没有标题栏?
当前回答
我在我的项目中使用这个
$("#myDialog").dialog(dialogOpts);
// remove the title bar
$("#myDialog").siblings('div.ui-dialog-titlebar').remove();
// one liner
$("#myDialog").dialog(dialogOpts).siblings('.ui-dialog-titlebar').remove();
其他回答
这招对我很管用:
$("#dialog").dialog({
create: function (event, ui) {
$(".ui-widget-header").hide();
},
我喜欢重写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
});
实际上还有另一种方法,直接使用对话框小部件:
您可以这样获得对话框小部件
$("#example").dialog(dialogOpts);
$dlgWidget = $('#example').dialog('widget');
然后做
$dlgWidget.find(".ui-dialog-titlebar").hide();
仅在该对话框中隐藏标题栏
并且在一行代码中(我喜欢链接):
$('#example').dialog('widget').find(".ui-dialog-titlebar").hide();
不需要在对话框中添加一个额外的类,直接就可以了。对我来说没问题。
当初始化对话框时,你可以使用jquery在使用dialogClass后隐藏标题栏。
init期间:
$('.selector').dialog({
dialogClass: 'yourclassname'
});
$('.yourclassname div.ui-dialog-titlebar').hide();
通过使用这种方法,你不需要改变你的css文件,这也是动态的。
如果你有多个对话框,你可以使用这个:
$("#the_dialog").dialog({
open: function(event, ui) {
//hide titlebar.
$(this).parent().children('.ui-dialog-titlebar').hide();
}
});
推荐文章
- 如何使用jQuery检测页面的滚动位置
- 如何在JSON中使用杰克逊更改字段名
- 在JavaScript中根据键值查找和删除数组中的对象
- 防止在ASP中缓存。NET MVC中使用属性的特定操作
- jQuery: keyPress退格键不火?
- XMLHttpRequest Origin null不允许Access-Control-Allow-Origin for file:/// to file:///(无服务器)
- 重置setTimeout
- jQuery有不聚焦的方法吗?
- jQuery -替换字符串中某个字符的所有实例
- Ng-repeat结束事件
- 模糊vs聚焦-有什么真正的区别吗?
- 如何用jQuery / JavaScript解析JSON数据?
- jQuery在请求体中发布有效的json
- jQuery中的live()转换为on()
- jQuery等价于JavaScript的addEventListener方法