如何在HTML工具提示中添加换行符?

我尝试在工具提示中使用<br/>和\n,如下所示:

<a href="#" title="Some long text <br/> Second line text \n Third line text">Hover me</a>

然而,这是无用的,我可以在工具提示中看到文字<br/>和\n。任何建议都会很有帮助。


当前回答

在文本之间给出\n。它适用于所有浏览器。

Example 
img.tooltip= " Your Text : \n"
img.tooltip += " Your text \n";

这将为我工作,它在后面的代码中使用。

希望这对你有用

其他回答

您可以使用引导工具提示,不要忘记将html选项设置为true。

<div id="tool"> tooltip</div>
$('#tool').tooltip({
     title: 'line one' +'<br />'+ 'line two',
     html: true
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

我找到了。只要这样简单地做就可以了

<a ref="#" title="First Line
                  Second Line
                  Third line">Hover Me</a>

在文本之间给出\n。它适用于所有浏览器。

Example 
img.tooltip= " Your Text : \n"
img.tooltip += " Your text \n";

这将为我工作,它在后面的代码中使用。

希望这对你有用

只需在脚本中添加以下代码片段:

    $(function () {
        $('[data-toggle="tooltip"]').tooltip()
    });

当然如上所述,data-html的答案应该是“真”。这将允许您在title属性的值内使用html标记和格式。

只需在标题中使用\n并添加这个CSS

.tooltip-inner {
    white-space: pre-wrap;
}