【问题标题】:How to pass line breaks through jQ.append()?如何通过 jQ.append() 传递换行符?
【发布时间】:2012-11-13 20:41:56
【问题描述】:

使用来自http://www.davidjrush.com/blog/2011/12/simple-jquery-tooltip/ 的一些简单jQ 逻辑来创建一个简单的工具提示效果。

但是,当我在 JQ 代码中添加换行符时,一切都变南了,逻辑停止工作 (FF)。

作品:

$(this).append('<div class="tooltip"><p>This is a tooltip. It is typically used to explain something to a user without taking up space on the page.</p></div>');

没有:

$(this).append('
<div class="tooltip"><p>This is a tooltip. It is typically used to explain something to a user without taking up space on the page.</p></div>
');

查看 jQ 文档,我找不到任何关于这是一个问题的信息。

任何人都知道它为什么会中断和/或我如何将换行符传递给 jQ.append()

【问题讨论】:

    标签: jquery html append line-breaks


    【解决方案1】:

    在追加内容中,您必须使用反斜杠跳过换行符。

    在你的情况下:

    $(this).append('\
    <div class="tooltip"><p>This is a tooltip. It is typically used to explain something to a user without taking up space on the page.</p></div>\
    ');

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 1970-01-01
      • 2016-04-02
      • 1970-01-01
      相关资源
      最近更新 更多