javascript - 更改 jquery ui 对话标题

标签 javascript jquery

我有这个 fiddle http://jsfiddle.net/cdG94/2/我在其中尝试更改 jquery UI 对话框标题..当我使用 Jquery 1.9 或更低版本时它工作正常但是当我转到更高版本的库时它只是直接显示 HTML..我在这里做错了什么.我正在使用Jquery 1.10.2 和 jQuery UI - v1.10.3

<button id="opener">Open the dialog</button>
<div id="wrapper">
<p>Some txt goes here</p>
</div>

$('#wrapper').dialog({
    autoOpen: false,
    minHeight: 400,
    minWidth: 600,
    title: function () {
                   return "Testing&nbsp<span style=\"font-size:smaller;\">Testing the HTML .</span>";
               }
});
$('#opener').click(function() {
    $('#wrapper').dialog('open');
    return false;
});

谢谢

最佳答案

在 jQuery UI 1.10 中,他们更改了 title 选项,以便它使用 .text() 而不是 .html() 来设置对话框的标题:

来自 jQuery UI 1.10 release notes :

Changed title option from HTML to text

(#6016) Dialog titles are controlled either via the title option or the title attribute on the content element. The title has previously been set as HTML, but since titles are generally plain text, this could easily cause a scripting vulnerability for users who don't realize the value is being set as HTML. As a result, titles are now set as text. If you need to add custom formatting to your dialog titles, you can override the _title() method on the dialog.

因此,要恢复到原始行为,您可以按照 jQuery UI 团队的建议 执行此操作:

$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
    _title: function (title) {
        if (!this.options.title) {
            title.html("&#160;");
        }
        title.html(this.options.title);
    }
}));

但请注意(如果您允许用户提供的输入出现在标题中)潜在的 XSS 漏洞是更改的最初原因!

(演示在 http://jsfiddle.net/alnitak/bJ47w/ )

关于javascript - 更改 jquery ui 对话标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19549577/

相关文章:

javascript - 指令不会在 AngularJS 中的选项卡选择/页面滚动时触发

javascript - Ajax 不发送文件

javascript - AngularJS 在 ie 11 的严格模式下不允许对只读属性赋值

php - 如何在一定时间后采取行动(因用户而异)?

javascript - Div 未显示,包含源

javascript - JQuery/PHP 表单未提交

jquery - 音频暂停/播放

javascript - Firebug : TypeError: 'click' called on an object that does not implement interface HTMLElement

javascript - 将不同尺寸的图像很好地融入拼贴画中

如果一个字母返回 true 的 Javascript 函数?