我有一个超长的jquery片段,我觉得可以用正确的逻辑进行简化。自从我终于开始工作以来,我很害怕接触它。如何简化if/else jquery片段
“else $ target = #none”实际上是“无显示”语句。我不确定如何以更好的方式表达这一点。
非常感谢! -zeem
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/',
});
});
你,我做到了,因为我无法弄清楚是怎么回事,以写else不要运行功能。 感谢您的回复!可悲的是,当我将它输入到网站时,它不起作用。 – zeemy23 2011-02-08 00:46:40