我有一个超长的 jquery 片段,我觉得可以用正确的逻辑来简化它。我害怕碰它,因为我终于让它工作了。
“else $target = #none”实际上是一个“什么都不显示”的声明。我不确定如何以更好的方式表达这一点。
非常感谢!-泽姆
PS。链接是医用大麻网站,所以 NSFW 链接!
$(function () {
var $target = $('#CO1');
if (mmjsRegion == 'CO') {
$target = $('#CO1');
} else {
$target = $('#none');
}
$target.imBannerRotater({
return_type: 'json',
data_map: {
image_name: 'name',
url_name: 'url'
},
image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CO1.php',
base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/',
});
});
$(function () {
var $target = $('#CO2');
if (mmjsRegion == 'CO') {
$target = $('#CO2');
} else {
$target = $('#none');
}
$target.imBannerRotater({
return_type: 'json',
data_map: {
image_name: 'name',
url_name: 'url'
},
image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CO2.php',
base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/',
});
});
$(function () {
var $target = $('#CO3');
if (mmjsRegion == 'CO') {
$target = $('#CO3');
} else {
$target = $('#none');
}
$target.imBannerRotater({
return_type: 'json',
data_map: {
image_name: 'name',
url_name: 'url'
},
image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CO3.php',
base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/',
});
});
$(function () {
var $target = $('#CA1');
if (mmjsRegion == 'CA') {
$target = $('#CA1');
} else {
$target = $('#none');
}
$target.imBannerRotater({
return_type: 'json',
data_map: {
image_name: 'name',
url_name: 'url'
},
image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CA1.php',
base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/',
});
});
$(function () {
var $target = $('#CA2');
if (mmjsRegion == 'CA') {
$target = $('#CA2');
} else {
$target = $('#none');
}
$target.imBannerRotater({
return_type: 'json',
data_map: {
image_name: 'name',
url_name: 'url'
},
image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CA2.php',
base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/',
});
});
$(function () {
var $target = $('#CA3');
if (mmjsRegion == 'CA') {
$target = $('#CA3');
} else {
$target = $('#none');
}
$target.imBannerRotater({
return_type: 'json',
data_map: {
image_name: 'name',
url_name: 'url'
},
image_url: 'http://www.kindreviews.com/wp-content/plugins/geoads/CA3.php',
base_path: 'http://www.kindreviews.com/wp-content/plugins/geoads/images/',
});
});