javascript - jQuery UI 对话框标题中的图标

标签 javascript jquery html css jquery-ui

我正在使用下面的代码创建一个 jQuery 对话框。默认情况下,标题栏上有一个关闭图标,但我想在标题栏中添加一些其他图标,以实现不同的功能。

对话框使用的代码是:

$("document").ready(function () {
    $("#dialog").dialog({
        title: "Dialog Title",
        height: 400,
        width: 500
    });
});

我正在使用以下 .css 和 .js 文件:

<link type="text/css" href="jquery-ui-1.7.3.custom.css" rel="stylesheet" />
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="jquery-ui-1.7.3.custom.min.js"></script>

最佳答案

您可以在创建对话框时在title 选项中定义HTML。因此,使用现有的 jQuery UI 图标 Sprite ,我们可以使用这个 Javascript:


对于 jQuery UI 1.10.0

根据 Bug #6016,您需要覆盖未记录的 _title 函数以确保 title 属性未被转义。

var dialog = $("#dialog").dialog();

dialog.data( "uiDialog" )._title = function(title) {
    title.html( this.options.title );
};

dialog.dialog('option', 'title', '<span class="ui-icon ui-icon-home"></span> Example Dialog');

对于旧版本

$("#dialog").dialog({
    title: '<span class="ui-icon ui-icon-home"></span> Example Dialog'
});

还有这个 CSS

.ui-dialog .ui-dialog-title .ui-icon {
    float: left;
    margin-right: 4px;
}

将图标添加到对话框的标题。您可以在此处查看完整的 jQuery UI 图标集:http://jqueryui.com/themeroller/

要实时查看此工作,请参阅:http://jsfiddle.net/XkSu9/ (jQuery UI 1.10+) 或 http://www.jsfiddle.net/yijiang/UYMJH/ (旧版本)

关于javascript - jQuery UI 对话框标题中的图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4103964/

相关文章:

javascript - 如何循环遍历状态中的相似对象并将它们推送到对象中?

javascript - 使用javascript更改字符串中最后一个字母的颜色

jQuery - 动画 css 背景大小?

javascript - onclick 函数在内联脚本中有效,但由于 window.onload = function() 而在外部 js 文件中无效。需要解决方法

javascript - 获取类的outerHeight并取最大值

javascript - Angular ng-repeat 变量可访问另一个作用域对象

javascript - 检查窗口打开

jquery - $(this) 和 this 有什么区别?

javascript - 纯javascript : Set border for draggable elements

javascript - 在 <img> 标签后插入文本