jQuery error: Uncaught ReferenceError: Invalid left-hand side in assignment
I'm using Chrome Developer Tools to debug a script. Its reporting the error:
Uncaught ReferenceError: Invalid left-hand side in assignment
doColor admin.php:292
$.get.theme 开发者_Go百科 admin.php:159
f.extend._Deferred.e.resolveWith jquery-1.6.1.min.js:16
w jquery-1.6.1.min.js:18
f.support.ajax.f.ajaxTransport.send.d jquery-1.6.1.min.js:18
The code is:
$('#my_theme').change
(
function()
{
$("#largePreview").hide();
var myImage = $('#my_theme :selected').text();
$('.selectedImage img').attr('src','<?php echo get_bloginfo('template_directory') ?>/styles/'+myImage+'/screenshot.jpg');
$('.selectedImage img').attr('title',myImage);
$.get('<?php echo get_bloginfo('template_directory') ?>/color.php', {theme: myImage, spot: '1'}, function(data){doColor('#theme_header_color', data);});
$.get('<?php echo get_bloginfo('template_directory') ?>/color.php', {theme: myImage, spot: '2'}, function(data){doColor('#theme_sidebar_color', data);});
$.get('<?php echo get_bloginfo('template_directory') ?>/color.php', {theme: myImage, spot: '3'}, function(data){doColor('#theme_spot_color_alt', data);});
$.get('<?php echo get_bloginfo('template_directory') ?>/color.php', {theme: myImage, spot: '4'}, function(data){doColor('#theme_spot_color_alt2', data);});
}
);
function doColor(el, color){
$(el).val(color).trigger('keyup');
$(el).attr('value', color);
$(el).val(color)=color;
}
This
$(el).val(color)=color;
should just be
$(el).val(color);
Although I cannot say whether this is the only problem. You are actually already setting the color two statements earlier with $(el).val(color).trigger('keyup');
.
$(el).attr('value', color);
also seems to be unnecessary if you are using val
. What are you trying to accomplish with these two lines?
$(el).val(color)=color;
You can't assign like this, it is a DOM element.
$(el).val(color); # This will set the value of the el element to the value of color.
精彩评论