我有一個超長的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