【问题标题】:convert the HTML tags to the HTML formatted display将 HTML 标记转换为 HTML 格式的显示
【发布时间】:2013-08-02 01:43:23
【问题描述】:

我在数据库中有一些 HTML 内容,并使用即兴作为灯箱来显示一些 html 内容。 希望它在哪里像

这是一个示例文本

但它显示为

<em><strong><span style="color: #ff6600;">This is a Sample Text</span></strong></em>

有没有办法将标记文本转换为格式化文本?

【问题讨论】:

  • 您需要显示更多代码。

标签: php javascript jquery html impromptu


【解决方案1】:

RTM,你可以使用 html: 方法来做到这一点

【讨论】:

    【解决方案2】:

    你应该会写

    $.prompt("<em><strong><span style='color: #ff6600;'>This is a Sample Text</span></strong></em>");
    

    参考:http://trentrichardson.com/Impromptu/

    虽然数据库中的 HTML 内容可能被转换为 HTML 字符引用。见http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

    【讨论】:

    • 它没有说明网站上的任何地方,它说明您需要使用 html 选项。
    • Quote: '消息可以是 html 字符串,也可以是“状态”对象'。状态有一个 html 选项 yes,但消息不需要存在状态。
    【解决方案3】:

    这是一个不依赖于 jQuery 的简单函数,它将完全按照您的要求进行转换:

    function str_to_html(text)
    {
        var a = document.createElement('div');
        a.innerHTML = text;
        return a.textContent;
    }
    
    // This function will convert '&lt;sometag&gt;' to '<sometag>', causing the markup
    // to be interpreted properly by the browser for your purpose.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-20
      • 2020-02-25
      • 2012-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-21
      相关资源
      最近更新 更多