jquery XML .html()而不是.text()不显示? [英] jquery XML .html() instead of .text() is not displaying?

查看:93
本文介绍了jquery XML .html()而不是.text()不显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚这个问题。我试图让XML来呈现HTML标记。我使用.text()的问题将显示但不能识别任何html标签。如果我使用.html()或者只是调用var long2 = $(this).find('long'); Safari或IE中不会显示任何内容。

我有xml段落

我在这里需要粗体标签或标签我>这就是为什么我需要在XML识别HTML标签。


代码:

  $(document)。 ready(function(){
$ .ajax({
type:GET,
url:xml / sites.xml,
dataType:xml,
success:function(xml){
$(xml).find('site')。each(function(){
var id = $(this).attr('id') ;
var title = $(this).find('title')。text();
var class = $(this).find('class')。text(); $ b $ ('< p class ='+ Class +'id =link_'+ id +'>< / div> '< / p>')。appendTo('#page-wrap');
$(this).find('desc')。each(function(){
var url = $( this).find('url')。text();
var long = $(this).find('long')。text();
$('< div class =长>< / DIV>')HTML(长) .appendTo('#link _'+ id);
$('#link _'+ id).append('< a href =http://'+ url +'>'+ url +'< ; / A>');
var long2 = $(this).find('long');
$('< div class =long2>< / div>')。html(long2).appendTo('#link _'+ id);

});
});
}
});


解决方案

.html()不适用于XML文档。您应该使用<![CDATA [您的代码在这里]]> 来包装XML文件。


I can't seem to figure out this problem. I am trying to get xml to render html tags. The problem I am having using .text() will display but not recognize any html tags. If I use .html() or just call var long2 = $(this).find('long'); nothing will show up in Safari or IE.

I have xml paragraph I have text in here that needs bold tags or tags which is why i need html tags in the xml to be recognized.

Code:

$(document).ready(function(){
        $.ajax({
            type: "GET",
            url: "xml/sites.xml",
            dataType: "xml",
            success: function(xml) {
                $(xml).find('site').each(function(){
                    var id = $(this).attr('id');
                    var title = $(this).find('title').text();
                    var Class = $(this).find('class').text();
                    $('<div class="'+Class+'" id="link_'+id+'"></div>').html('<p class="title">'+title+'</p>').appendTo('#page-wrap');
                    $(this).find('desc').each(function(){
                        var url = $(this).find('url').text();
                        var long = $(this).find('long').text();
                        $('<div class="long"></div>').html(long).appendTo('#link_'+id);
                        $('#link_'+id).append('<a href="http://'+url+'">'+url+'</a>');
                             var long2  = $(this).find('long');
                             $('<div class="long2"></div>').html(long2).appendTo('#link_'+id);

                    });
                });
            }
        });

解决方案

.html() does not work with XML documents. You should wrap the HTML content in the XML file with <![CDATA[your code here]]>.

这篇关于jquery XML .html()而不是.text()不显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆