我遇到了如何使用xml解析多个图像的问题。我得到的错误是它在一个img中重复所有图像数据。
$(document).find('slider > image').each(function(){
var img = $(document).find("slider > image > src").text();
var desc = $(document).find("slider > image > description").text();
$("<img src='"+img+"' alt='"+desc+"' />").appendTo('slider');
});
例如。
<img alt="The Last of usGTA VMirror Edge" src="assets/images/fullimage1.jpgassets/images/fullimage2.jpgassets/images/fullimage3.jpg">
<img alt="The Last of usGTA VMirror Edge" src="assets/images/fullimage1.jpgassets/images/fullimage2.jpgassets/images/fullimage3.jpg">
<img alt="The Last of usGTA VMirror Edge" src="assets/images/fullimage1.jpgassets/images/fullimage2.jpgassets/images/fullimage3.jpg">
这是xml语法
<carousal>
<slider>
<image>
<src>assets/images/fullimage1.jpg</src>
<description>The Last of us</description>
</image>
<image>
<src>assets/images/fullimage2.jpg</src>
<description>GTA V</description>
</image>
<image>
<src>assets/images/fullimage3.jpg</src>
<description>Mirror Edge</description>
</image>
</slider>
</carousal>
这是html
<slider></slider>