我目前正在为我们的网站添加冗长的工具提示,我想(不必求助于一个神奇的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#)
以上方法都行不通。这可能吗?
当前回答
值得一提的是,如果你用JavaScript设置title属性,如下所示:
divElement。setAttribute("title", "第一行 第二行");
这是行不通的。你必须将ASCII十进制10替换为ASCII十六进制a按照JavaScript转义的方式。是这样的:
divElement。setAttribute("title", "Line one\x0ALine two");
其他回答
从Firefox 12开始,他们现在支持使用换行HTML实体的换行:
<span title="First line Second line">Test</span>
这在IE中工作,并且根据HTML5的title属性规范是正确的。
在寻找在引导工具提示中显示断线的解决方案时,我被引导到此页面。当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中测试。
& # 013;如果只使用简单的title属性,应该可以工作。
在Bootstrap弹窗中,只需使用data-html="true"并在data-content属性中使用HTML。
<div title=“Hello World”>悬停在这里</div>
在Chrome 16或更早的版本中,你可以使用“\n”。顺便说一句,“\t”也可以。
我们有一个需求,我们需要测试所有这些,下面是我想分享的:
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/>
小提琴