我有一个这样的json文件:
{
"video": {
"default" : {
"url": "http://showmms.rd.llnwd.net/d4/u/video/mezzanine/mov/1002742_1_0_trl02.mov",
"imgSm": "http://www.sho.com/assets/vendor/sxsw/img/iphone-video.png",
"imgLg": "http://www.sho.com/assets/vendor/sxsw/img/video-img.jpg",
"imgTitle": "http://www.sho.com/assets/vendor/sxsw/img/video-title.jpg"
},
"mar8" : {
"url": "http://showmms.rd.llnwd.net/d4/u/video/mezzanine/mov/1002742_1_0_trl02.mov",
"imgSm": "http://www.sho.com/assets/vendor/sxsw/img/promos/SXSW2013_VOD_Banners_Dexter_Small_320x41.png",
"imgLg": "http://www.sho.com/assets/vendor/sxsw/img/promos/SXSW2013_VOD_Banners_Dexter_Large_320x264.png",
"imgTitle": "http://www.sho.com/assets/vendor/sxsw/img/video-title.jpg"
},
"mar9" : {
"url": "http://showmms.rd.llnwd.net/d4/u/video/mezzanine/mov/1002742_1_0_trl02.mov",
"imgSm": "http://www.sho.com/assets/vendor/sxsw/img/iphone-video.png",
"imgLg": "http://www.sho.com/assets/vendor/sxsw/img/video-img.jpg",
"imgTitle": "http://www.sho.com/assets/vendor/sxsw/img/video-title.jpg"
}
}
}
}
所以根据日期,它应该显示正确的图像和 url。但如果它与日期不匹配,它应该使用“默认”,我的 jquery 不工作,但我不知道为什么:
var today = new Date();
var dd = today.getDate();
var promo = 'mar' + dd;
var imgLg = data.video[promo].imgLg;
var imgSm = data.video[promo].imgSm;
var url = data.video[promo].url;
promo = data.video[promo] ? promo : 'default';
$("img.video-lg").attr("src",imgLg);
$("img.video-sm").attr("src",imgSm);
$("a.play-btn").attr("href",url);
如果日期匹配,它可以工作,但如果不匹配,它不会拉入“默认”