gpt4 book ai didi

javascript - 更改 jquery ui 对话标题

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:48:48 25 4
gpt4 key购买 nike

我有这个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com