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

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

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

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


当前回答

嗨,这段代码将在所有浏览器中工作!!我使用 用于chrome和safari的新产品线和IE的ul li

 function genarateMultiLIneCode(){
        var =values["a","b","c"];
        const liStart = '<li>';
              const liEnd = '</li>';
              const bullet = '&#8226; ';     
              var mergedString = ' ';
              const unOrderListStart='<ul>'
              const unOrderListEnd='</ul>'
              const fakeNewline = '&#013;&#010;';
              for (let i = 0; i < values.length; i++) {
                   mergedString += liStart + bullet + values[i] + liEnd + fakeNewline;
              }
              const tempElement = document.createElement("div");
              tempElement.innerHTML = unOrderListStart + mergedString + unOrderListEnd;    
              return tempElement.innerText;
            }
        }

其他回答

在原生HTML工具提示中添加换行符是可能的,只需将标题属性分布在多行中即可。

但是,我建议使用jQuery工具提示插件,如Q-Tip: http://craigsworks.com/projects/qtip/。

它的设置和使用都很简单。另外,也有很多免费的javascript工具提示插件。

编辑:第一个语句的更正。

您可以使用引导工具提示,不要忘记将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>

这个CSS是我在编辑器中与换行一起工作的最终结果:

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

在这里找到: 如何使Twitter引导工具提示有多行?

嗨,这段代码将在所有浏览器中工作!!我使用 用于chrome和safari的新产品线和IE的ul li

 function genarateMultiLIneCode(){
        var =values["a","b","c"];
        const liStart = '<li>';
              const liEnd = '</li>';
              const bullet = '&#8226; ';     
              var mergedString = ' ';
              const unOrderListStart='<ul>'
              const unOrderListEnd='</ul>'
              const fakeNewline = '&#013;&#010;';
              for (let i = 0; i < values.length; i++) {
                   mergedString += liStart + bullet + values[i] + liEnd + fakeNewline;
              }
              const tempElement = document.createElement("div");
              tempElement.innerHTML = unOrderListStart + mergedString + unOrderListEnd;    
              return tempElement.innerText;
            }
        }

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

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