在下面的代碼分支中,當更改「my_theme」選擇菜單時,我正在對服務器進行幾次$ get調用以檢索所選內容主題的默認顏色選項和預覽圖像。在此過程中,爲避免用戶在加載顏色之前單擊「應用更改」按鈕,我將該按鈕設置爲禁用,然後在操作完成後將其重置。
但是,在一次安裝中,某些顯然失敗的按鈕將保持禁用狀態(即使get操作沒有明顯錯誤)。
我怎樣才能更好地構造這個以完成獲取完成後重命名提交按鈕?
$('#my_theme').change
(
function()
{
$("#largePreview").hide();
var myImage = $('#my_theme :selected').val();
var thisOption = $(this);
$('.selectedImage img').attr('src','<?php echo get_bloginfo('template_directory') ?>/styles/'+myImage+'/screenshot.jpg');
$('.selectedImage img').attr('alt',myImage);
try{
$('button.save').attr('disabled','disabled');
$.get('<?php echo get_bloginfo('template_directory') ?>/color.php', {theme: myImage, spot: '1'}, function(data){doColor('#my_theme_header_color', data);});
$.get('<?php echo get_bloginfo('template_directory') ?>/color.php', {theme: myImage, spot: '2'}, function(data){doColor('#my_theme_sidebar_color', data);});
$.get('<?php echo get_bloginfo('template_directory') ?>/color.php', {theme: myImage, spot: '3'}, function(data){doColor('#my_theme_spot_color_alt', data);});
$.get('<?php echo get_bloginfo('template_directory') ?>/color.php', {theme: myImage, spot: '4'}, function(data){doColor('#my_theme_spot_color_alt2', data);});
$.get('<?php echo get_bloginfo('template_directory') ?>/color.php', {theme: myImage, spot: '5'}, function(data){doColor('#my_bg_attach_color', data);});
}
catch(e){
$('button.save').attr('disabled','');
}
$.get('<?php echo get_bloginfo('template_directory') ?>/get-image.php', {template: myImage, action: 'background'}, function(data){
if(data){$('#currentBackgroundImage').attr('src','<?php echo get_bloginfo('template_directory') ?>/styles/'+myImage+'/background.png');}
else{$('#currentBackgroundImage').attr('src','<?php echo get_bloginfo('template_directory') ?>/background-missing.png');}
});
$.get('<?php echo get_bloginfo('template_directory') ?>/get-image.php', {template: myImage, action: 'header'}, function(data){
if(data){$('#currentHeaderImage').attr('src','<?php echo get_bloginfo('template_directory') ?>/styles/'+myImage+'/header.png');}
else{$('#currentHeaderImage').attr('src','<?php echo get_bloginfo('template_directory') ?>/header-missing.png');}
$('button.save').attr('disabled','');
});
});
+1感謝您的多種選擇。 – RegEdit 2012-04-18 12:15:58