使用jQuery从CDATA和描述标签中获取图像 [英] get image out of CDATA and description tag with jquery

查看:103
本文介绍了使用jQuery从CDATA和描述标签中获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从CDATA和描述标签中获取图像? 这是XML代码:

How do i get a image out of a CDATA and description tag? Here is the XML code:

<description>
    <![CDATA[
        <img src='http://www.autowereld.com/imagesDB/100/311151018460_.jpg' border='0'                     bordercolor='black' style='float:left; margin-right: 8px;margin-bottom: 8px;'>
    ]]>

    Het is Subaru wat de klok slaat deze week. Na spyshots van de Subaru Legacy Touring,     gelekte foto’s van de productierijpe WRX en de officiële bekendmaking van de Legacy Concept is     het nu tijd voor de Crossover 7 Concept.
</description>

这就是我得到的:

var img = $(element).find("description").text();
img = img.replace("<![CDATA[", "").replace("]]>", "");
console.log(img);
$("#img").append('<img src="' + img + '">');

推荐答案

您尝试过:

var img = $(element).find("description").text();
        img = img.replace("<![CDATA[", "").replace("]]>", "");
        console.log(img);
        $("#img").append(img); // <-- use only the var ing

从描述标签中删除CDATA和图像标签:

to remove the CDATA and image tag out of the description tag :

var dsr = $(element).find("description").text();
dsr= dsr.substring(dsr.indexOf('>')+1, dsr.length);

这篇关于使用jQuery从CDATA和描述标签中获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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