【问题标题】:display new lines from xml to html using jquery使用 jquery 显示从 xml 到 html 的新行
【发布时间】:2010-12-13 18:49:17
【问题描述】:

我想通过 jquery 显示从 xml 到 html 的数据

我有段落格式的 xml 数据,但由于 html 的默认行为,它无法显示“输入”形式的行。

请建议我如何确保它会开始显示。

我的查询与这里已经完成的链接非常相​​似。

但我不知道如何在 html/javascript 中做到这一点

Read xml string into textbox with newline

提前致谢
戴夫

【问题讨论】:

    标签: javascript jquery html


    【解决方案1】:

    如果您要插入缩进的 XML 代码,您可以使用容器上的 white-space: pre CSS 属性来显示换行符:

    <p style="white-space: pre" id="xmlCode"></p>
    

    而在 jQuery 中只需设置文本:

    $('#xmlCode').text(xmlContent);
    

    【讨论】:

    • 对不起,应该是white-space: pre;我确定了答案。
    • 感谢 Krof,它正在工作,但它没有采用 xml 中的“Enter”。它只延续到一行
    • 除非您要手动换行,否则您无法使用pre 空格进行自动换行。您可以在p 元素上设置overflow-x: auto; overflow-y: hidden,以在线条超出宽度时显示水平滚动条。
    • “Enter”字符的 ASCII 码是什么?听起来你没有使用\n\r\n
    • 在页面中直接显示\r\n
    【解决方案2】:

    我只是将 iwantenter 插入到 xml 文件中,无论我需要输入什么

    在将文本分配给 div 之后

    我调用了这个函数

    id_of_my_div.replace(/iwantenter/g,'

    ');它奏效了

    感谢 Krof 继续回复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多