我正在尝试object
使用. 不幸的是,我无法做到这一点。我在下面粘贴我的代码。ul li
jQuery
var photos = [];
$( "#sliderContent li" ).each(function() {
var title = $(this).find(".title").html();
var image = $(this).find(".image".html());
var url = $(this).find(".url").html();
var firstline = $(this).find(".firstline").html();
var secondline = $(this).find(".secondline").html();
var slide = new Object();
slide.title = title;
slide.image = image;
slide.url = url;
slide.firstline = firstline;
slide.secondline = secondline;
photos.push(slide);
});
我的 HTML 列表ul li
<ul id="sliderContent" >
<li>
<div class="title">Stairs 1</div>
<div class="image">vacation.jpg 1</div>
<div class="url"># 1</div>
<div class="firstline">Amazing Apartment for Rent in JBR 1</div>
<div class="secondline">
<div class='row'>
<div class='col1'>ABD 1</div>
<div class='col2'>EFG 1</div>
</div>
<div class='row'>
<div class='col1'>ABD 1</div>
<div class='col2'>EFG 1</div>
</div><div class='row'>
<a class='view' href='#'></a>
<a class='arrange' href='#'></a>
</div>
</div>
</li>
</ul>
这就是我想要创建的。
var photos = [ {
"title" : "Stairs",
"image" : "vacation.jpg",
"url" : "",
"firstline" : "Amazing Apartment for Rent in JBR",
"secondline" : "lorem ipsum"
}, {
"title" : "Office Appartments",
"image" : "work.jpg",
"url" : "",
"firstline" : "Amazing Apartment for Rent in JBR",
"secondline" : "work?"
}];
请告诉我哪里出错了,以及如何查看数组的内容photos
来检查结果。
任何帮助,将不胜感激。