今天,我用jQuery 1.9.1升级了所有jQuery插件.我开始在jquery中使用jQueryUI工具提示.用户界面.1.10.2. 一切都很好.但是当我在内容中使用HTML标记时(在我应用工具提示的元素的title
属性中),我注意到HTML不受支持.
这是我的工具提示的屏幕截图:
How can I make HTML content work with jQueryUI tooltip in 1.10.2?
今天,我用jQuery 1.9.1升级了所有jQuery插件.我开始在jquery中使用jQueryUI工具提示.用户界面.1.10.2. 一切都很好.但是当我在内容中使用HTML标记时(在我应用工具提示的元素的title
属性中),我注意到HTML不受支持.
这是我的工具提示的屏幕截图:
How can I make HTML content work with jQueryUI tooltip in 1.10.2?
Edit:由于这是一个流行的答案,我在下面的 comments 中添加了@crush提到的免责声明.如果你用这个方法,be aware that you're opening yourself up for an XSS vulnerability.仅当您在属性中包含know what you're doing和certain个HTML内容时,才使用此解决方案.
The easiest way to do this is to supply a function to the content
option that overrides the default behavior:
$(function () {
$(document).tooltip({
content: function () {
return $(this).prop('title');
}
});
});
Example: http://jsfiddle.net/Aa5nK/12/
Another option would be to override the tooltip widget with your own that changes the content
option:
$.widget("ui.tooltip", $.ui.tooltip, {
options: {
content: function () {
return $(this).prop('title');
}
}
});
现在,每次你拨打.tooltip
,HTML内容都会被返回.
Example: http://jsfiddle.net/Aa5nK/14/