我有以下脚本,我无法找到如何使用汽车[0] ['img']内的值$('#img2')。attr('src ”,车[0] [ 'IMG']); 即时通讯JS的noob所以请解释我..为什么jQuery不会接受2d数组作为字符串值和运行该功能,以及我的问题可能的解决方案是什么?jquery atrr +二维数组问题
var id = 0 ;
var car = new Array();
car[0]['img'] = "./images/carousel_img_2.jpg";
car[0]['title'] ="title";
car[0]['desc'] = 'longer description goes here';
car[0]['link'] = "http://goeshere.com";
car[1]['img'] = "./images/carousel_img_3.jpg";
car[1]['title'] ='title';
car[1]['desc'] = 'longer description goes here';
car[1]['link'] = "http://goeshere.com";
car[2]['img'] = "./images/carousel_img_2.jpg";
car[2]['title'] ='title';
car[2]['desc'] = 'longer description goes here';
car[2]['link'] = "http://goeshere.com";
function nxt() {
$('#img2').fadeOut('slow', function(){
var img = car[i]['img'] ;
$('#img2').attr('src',img);
});
$('#img2').fadeIn('slow');
}
也被称为JavaScript Object Notation :) – 2009-09-22 00:38:06
正确!更多信息:http://www.json.org – 2009-09-22 00:42:40
我改变了我的数组的定义后,它像一个魅力工作:)谢谢! – Aviatrix 2009-09-22 00:46:19