我有我的 json 脚本,它可以获取我的类别并将其放入 nivo 滑块中。效果很好。
(function() {
var url = 'http://my url.com/blog/?category=gw-preview&format=json&callback=?';
$.getJSON(url).done(function(data) {
for(var i = 0; i < 1; i++){
if(data.items[i] != null){
var current = data.items[i];
var post = '<li><a href="http://my url.com/' + current.fullUrl + '"><img src= "'+current.assetUrl+'" alt ="'+current.filename+'"></a></li>' ;
$('ul.slides').append(post);
}
}
});
})();
(function() {
var url = 'http://my url.com/blog/?category=gw-news&format=json&callback=?';
$.getJSON(url).done(function(data) {
for(var i = 0; i < 1; i++){
if(data.items[i] != null){
var current = data.items[i];
var post = '<li><a href="http://my url.com/' + current.fullUrl + '"><img src= "'+current.assetUrl+'" alt ="'+current.filename+'"></a></li>' ;
$('ul.slides').append(post);
}
}
});
})();
(function() {
var url = 'http://my url.com/blog/?category=captaincy-analysis&format=json&callback=?';
$.getJSON(url).done(function(data) {
for(var i = 0; i < 1; i++){
if(data.items[i] != null){
var current = data.items[i];
var post = '<li><a href="http://my url.com/' + current.fullUrl + '"><img src= "'+current.assetUrl+'" alt ="'+current.filename+'"></a></li>' ;
$('ul.slides').append(post);
}
}
});
})();
(function() {
var url = 'http://my url.com/blog/?category=pundits-team&format=json&callback=?';
$.getJSON(url).done(function(data) {
for(var i = 0; i < 1; i++)
{
if(data.items[i] != null)
{
var current = data.items[i];
var post = '<li><a href="http://my url.com/' + current.fullUrl + '"><img src= "'+current.assetUrl+'" alt ="'+current.filename+'"></a></li>' ;
$('ul.slides').append(post);
}
}
});
})();
(function() {
var url = 'http://my url.com/blog/?category=strategy&format=json&callback=?';
$.getJSON(url).done(function(data) {
for(var i = 0; i < 1; i++)
{
if(data.items[i] != null)
{
var current = data.items[i];
var post = '<li><a href="http://my url.com/' + current.fullUrl + '"><img src= "'+current.assetUrl+'" alt ="'+current.filename+'"></a></li>' ;
$('ul.slides').append(post);
}
}
});
})();
(function() {
var url = 'http://my url.com/blog/?category=new-signings&format=json&callback=?';
$.getJSON(url).done(function(data) {
for(var i = 0; i < 1; i++)
{
if(data.items[i] != null)
{
var current = data.items[i];
var post = '<li><a href="http://my url.com/' + current.fullUrl + '"><img src= "'+current.assetUrl+'" alt ="'+current.filename+'"></a></li>' ;
$('ul.slides').append(post);
}
}
});
})();
我将如何制作更轻量级,我只是编译它以使其缩小吗?或者是他们的部分我可以更好。对我来说,它看起来有点重,但没有专业知识,我真的不知道选项