如何在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。任何建议都会很有帮助。
当前回答
嗨,这段代码将在所有浏览器中工作!!我使用 用于chrome和safari的新产品线和IE的ul li
function genarateMultiLIneCode(){
var =values["a","b","c"];
const liStart = '<li>';
const liEnd = '</li>';
const bullet = '• ';
var mergedString = ' ';
const unOrderListStart='<ul>'
const unOrderListEnd='</ul>'
const fakeNewline = '
';
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;
}
}
其他回答
Jquery UI 1.10不支持在标题属性中使用html标签,因为它不是有效的html。
所以另一种解决方案是使用工具提示内容选项。 参考- http://api.jqueryui.com/tooltip/#option-content
只需添加data-html="true"
<a href="#" title="Some long text <br/> Second line text \n Third line text" data-html="true">Hover me</a>
\n
在造型上
.tooltip-inner {
white-space: pre-line;
}
为我工作。
我找到了。只要这样简单地做就可以了
<a ref="#" title="First Line
Second Line
Third line">Hover Me</a>
在文本之间给出\n。它适用于所有浏览器。
Example
img.tooltip= " Your Text : \n"
img.tooltip += " Your text \n";
这将为我工作,它在后面的代码中使用。
希望这对你有用