这是我的数组,我需要做一个foreach来显示每个图像等.基本上数组包含幻灯片和幻灯片信息,我需要输入一个包含信息的div(如果我知道如何访问它,我可以这样做).
var slides = new Array();
slides[1] = {slidetitle: 'title 1',
slidetext: 'text 1',
image1: '',
magnifyposit: '',
buttontext: 'button text 1',
buttonurl: 'http://www.google.com'};
slides[2] = {slidetitle: 'title 2',
slidetext: 'text 2',
image1: '',
magnifyposit: '',
buttontext: 'button text 2',
buttonurl: 'http://www.google.com'};
slides[3] = {slidetitle: 'title 3',
slidetext: 'text 3',
image1: '',
magnifyposit: '',
buttontext: 'button text 3',
buttonurl: ''};
slides[4] = {slidetitle: 'title 4',
slidetext: 'text 4',
image1: '',
magnifyposit: '',
buttontext: 'button text 4',
buttonurl: 'http://www.google.com'};
slides[5] = {slidetitle: 'title 5',
slidetext: 'text 5',
image1: '',
magnifyposit: '',
buttontext: 'button text 5',
buttonurl: 'http://www.google.com'};
Run Code Online (Sandbox Code Playgroud)
你可以像这样使用$ .each
$.each(slides,function(i,obj){
//here obj is object element of slides array
// access properties of the object
// in current iteration like obj.slidetitle,obj.slidetext etc
});
Run Code Online (Sandbox Code Playgroud)
注意:您应该从0开始数组索引.
| 归档时间: |
|
| 查看次数: |
114 次 |
| 最近记录: |