我目前正在为我们的网站添加冗长的工具提示,我想(不必求助于一个神奇的jQuery插件,我知道有很多!)使用回车来格式化工具提示。
为了添加提示,我使用了title属性。我环顾了一下常用的网站,并使用了基本的模板:
<a title='Tool?Tip?On?New?Line'>link with tip</a>
我试过更换?:
< br / > &013;/ & # 13; \ r \ n 环境。换行符(我使用c#)
以上方法都行不通。这可能吗?
我目前正在为我们的网站添加冗长的工具提示,我想(不必求助于一个神奇的jQuery插件,我知道有很多!)使用回车来格式化工具提示。
为了添加提示,我使用了title属性。我环顾了一下常用的网站,并使用了基本的模板:
<a title='Tool?Tip?On?New?Line'>link with tip</a>
我试过更换?:
< br / > &013;/ & # 13; \ r \ n 环境。换行符(我使用c#)
以上方法都行不通。这可能吗?
当前回答
这里是一个演示:http://jsfiddle.net/rzea/vsp6840b/3/
HTML使用:
<a href="#" title="First Line
Second Line">Multiline Tooltip</a>
<br>
<br>
<a href="#" title="List:
• List item here
• Another list item here
• Aaaand another list item, lol">Unordered list tooltip</a>
其他回答
“只需按下enter”的解决方案在这里不起作用,所以优秀的老香草JavaScript似乎是一种相当高效和干净的方法。
function customTitle(event, textHeader, text){
let eventOrigin = event.target || event.srcElement;
eventOrigin.title = textHeader + '\n\n' + text;
}
在元素onmouseover上:
onmouseover="customTitle(event, 'Some Caput', 'Some more or less complete description');"
瞧!它适用于谷歌Chrome和Firefox(不排除其他;我只是没有检查)。
在寻找在引导工具提示中显示断线的解决方案时,我被引导到此页面。当data-toggle="tooltip"被添加到HTML标签中时,引导工具提示将显示出来。
最后,我发现一个data-html="true"应该被添加到标签中,这样做你的标题内的HTML将被呈现。然后使用<br>来breakline。检查下面的示例:
之前(未显示任何折线):
<i class="bi bi-x-circle" data-toggle="tooltip" data-placement="top" title="test1 <br> test2"></i>
After(显示折线):
<i class="bi bi-x-circle" data-toggle="tooltip" data-html="true" data-placement="top" title="test1 <br> test2"></i>
- Laravel和Blade程序员的提示:你可以用nl2br("string")函数将\n转换为<br>。
-以上解决方案已在谷歌Chrome 98中测试。
我们有一个需求,我们需要测试所有这些,下面是我想分享的:
document.getElementById("tooltip").setAttribute("title", "Tool\x0ATip\x0AOn\x0ANew\x0ALine") <p title='Tool Tip On New Line'>Tooltip with <pre> new line</pre> Works in all browsers</p> <hr/> <p title="Tool Tip On New Line">Tooltip with <code>&#13;</code> Not works Firefox browsers</p> <hr/> <p title='Tool Tip On New Line'>Tooltip with <code>&#10;</code> Works in some browsers</p> <hr/> <p title='Tool
Tip
On
New
Line'>Tooltip with <code>&#xD;</code> May work in some browsers</p> <hr/> <p id='tooltip'>Tooltip with <code>document.getElementById("tooltip").setAttribute("title", "Tool\x0ATip\x0AOn\x0ANew\x0ALine")</code> May work in some browsers</p> <hr/> <p title="List: • List item here • Another list item here • Aaaand another list item, lol">Tooltip with <code>• </code>Unordered list tooltip</p> <hr/> <p title='Tool\nTip\nOn\nNew\nLine'>Tooltip with <code>\n</code> May not work in modern browsers</p> <hr/> <p title='Tool\tTip\tOn\tNew\tLine'>Tooltip with <code>\t</code> May not work in modern browsers</p> <hr/> <p title='Tool
Tip
On
New
Line'>Tooltip with <code>&#013;</code> Works in most browsers</p> <hr/>
小提琴
有多种方法可以做到这一点。
或
取决于浏览器。但下面的例子适用于我的谷歌Chrome和Firefox。
<a href="javascript:;" title="工具提示第一行 工具提示第二行 工具提示第三行">工具提示</a> .
最新的规范允许换行字符,因此在属性或实体
中使用简单的换行符;(注意字符#和;是必需的)都可以。