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

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

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

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


当前回答

只需使用实体代码&#xA;用于标题属性中的换行符。

<a title="First Line &#xA;Second Line">Hover Me </a>

其他回答

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

只需添加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;
}

为我工作。

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

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

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

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

我的解决方案是http://jqueryui.com/tooltip/:

这里的代码(脚本中使<br/>工作的部分是"content:"):

HTML头

<head runat="server">
    <script src="../Scripts/jquery-2.0.3.min.js"></script>
    <link href="Content/themes/base/jquery-ui.css" rel="stylesheet" />
    <script src="../Scripts/jquery-ui-1.10.3.min.js"></script>
<script>
    /*Position:
      my =>  at
      at => element*/
    $(function () {
        $(document).tooltip({
            content: function() {
                var element = $( this );
                if ( element.is( "[title]" ) ) {
                    return element.attr( "title" );
                }

            },
            position: { my: "left bottom-3", at: "center top" } });
    });
</script>
</head>

ASPX或HTML控件

<asp:TextBox ID="Establecimiento" runat="server" Font-Size="1.3em" placeholder="Establecimiento" title="Texto 1.<br/>TIP: texto 2"></asp:TextBox>

希望这对大家有所帮助