如何在HTML工具提示中添加换行符?
我尝试在工具提示中使用<br/>和\n,如下所示:
<a href="#" title="Some long text <br/> Second line text \n Third line text">Hover me</a>
然而,这是无用的,我可以在工具提示中看到文字<br/>和\n。任何建议都会很有帮助。
如何在HTML工具提示中添加换行符?
我尝试在工具提示中使用<br/>和\n,如下所示:
<a href="#" title="Some long text <br/> Second line text \n Third line text">Hover me</a>
然而,这是无用的,我可以在工具提示中看到文字<br/>和\n。任何建议都会很有帮助。
当前回答
如果你使用jquery-ui 1.11.4:
var tooltip = $.widget( "ui.tooltip", {
version: "1.11.4",
options: {
content: function() {
// support: IE<9, Opera in jQuery <1.7
// .text() can't accept undefined, so coerce to a string
var title = $( this ).attr( "title" ) || "";
// Escape title, since we're going from an attribute to raw HTML
Replace--> //return $( "<a>" ).text( title ).html();
by --> return $( "<a>" ).html( title );
},
其他回答
& # 013;结合样式留白:行前;为我工作。
只需在脚本中添加以下代码片段:
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
当然如上所述,data-html的答案应该是“真”。这将允许您在title属性的值内使用html标记和格式。
只需使用实体代码
用于标题属性中的换行符。
\n
在造型上
.tooltip-inner {
white-space: pre-line;
}
为我工作。
我找到了。只要这样简单地做就可以了
<a ref="#" title="First Line
Second Line
Third line">Hover Me</a>