在下面的代码分支中,当“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','');
});
});