Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-从解析的xml提要(内容:encoded)获取第一个图像_Jquery_Xml Parsing - Fatal编程技术网

jQuery-从解析的xml提要(内容:encoded)获取第一个图像

jQuery-从解析的xml提要(内容:encoded)获取第一个图像,jquery,xml-parsing,Jquery,Xml Parsing,我能够使用以下代码搜索XML提要 $($xml).find('item').each(function(i, e) { ... } 对于这个循环中的每个项目,我都可以访问我的content:encoded元素,并查看结果 $mcontent = $(this).find('encoded').text(); console.log('source: ' + $mcontent.match(/<img[^>]*>/g)); 如果你的文字是: Uncaught

我能够使用以下代码搜索XML提要

$($xml).find('item').each(function(i, e) { ... }
对于这个循环中的每个项目,我都可以访问我的content:encoded元素,并查看结果

    $mcontent = $(this).find('encoded').text();
    console.log('source: ' + $mcontent.match(/<img[^>]*>/g));
如果你的文字是:

Uncaught TypeError: $mcontent.match(...).split is not a function

您可以使用:

<p><img src="...">, <img src="...">, <img src="..."></p>
var str=',

; var firstImg=$($.parseHTML(str)[0]).find('img:first');
未捕获类型错误:$mcontent.match(…)。拆分不是函数

发生这种情况的原因是“$mcontent.match(/]>/g)”*返回一个img数组,您就可以得到第一个元素:

片段:

var str=',

; var firstImg=$($.parseHTML(str)[0]).find('img:first'); console.log(firstImg[0].outerHTML); 如果您的文本是:

Uncaught TypeError: $mcontent.match(...).split is not a function

您可以使用:

<p><img src="...">, <img src="...">, <img src="..."></p>
var str=',

; var firstImg=$($.parseHTML(str)[0]).find('img:first');
未捕获类型错误:$mcontent.match(…)。拆分不是函数

发生这种情况的原因是“$mcontent.match(/]>/g)”*返回一个img数组,您就可以得到第一个元素:

片段:

var str=',

; var firstImg=$($.parseHTML(str)[0]).find('img:first'); console.log(firstImg[0].outerHTML);
var t=str.match(/
“您的图像,字符串,此处”。拆分(',')[0]会将第一个图像作为字符串提供给您。在尝试实现这一点时,我在上面还有一个问题……我还忘记了原始版本中的一个元素……感谢axel提醒您拆分“您的图像,字符串,此处”。拆分(',)[0]我在上面还有一个问题,在尝试实现这一点时…我还忘记了我的原始版本中的一个元素…感谢axel在split上的提醒
var str = '<p><img src="...">, <img src="...">, <img src="..."></p>';
var firstImg = $($.parseHTML(str)[0]).find('img:first');