【问题标题】:A HREF Content in XML not loaded as link when dynamically generated using JQuery使用 JQuery 动态生成时,XML 中的 HREF 内容未作为链接加载
【发布时间】:2012-11-26 19:25:08
【问题描述】:

我有一个 XML 文件,它在 XML 子标签中包含一些 Anchor(A HREFs) 标签......当我使用 JQuery 加载内容并生成动态 HTML 元素时,链接不会出现。

示例 XML 标记:

<question>
    <number>12</number>
    <qts>How can I download the mobile app?</qts>
    <ans>Please login to the site – <a href="https://google.com">https://google.com</a> from your desktop/laptop. Go to the subscribe page and download the file that is appropriate for you.</ans> 
</question>

JQuery 标签加载:

xml_ans = $(this).find('ans').text();

问题是https://google.com 没有显示为链接。

任何人都可以给它一些启示或提示吗?

【问题讨论】:

  • 内容现在显示为链接...我忘记了这个概念...当您添加数据时,内容将作为 HTML 处理,否则如果您不添加 CDATA 标记,则内容将被处理为纯文本...

标签: jquery html xml hyperlink anchor


【解决方案1】:

使用&lt;![CDATA[ ]]&gt; 将您的 HTML 封装在 XML 中;

<question>
        <number>12</number>
        <qts>How can I download the mobile app?</qts>
        <ans>
                <![CDATA[
                    Please login to the site – <a href="https://google.com">https://google.com</a> from your desktop/laptop. Go to the subscribe page and download the file that is appropriate for you.
                ]]>
        </ans>  
</question>

http://en.wikipedia.org/wiki/CDATA

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-28
  • 2011-06-14
相关资源
最近更新 更多