开发者

Syntax? Set string variable to string value when element is clicked

开发者 https://www.devze.com 2023-03-06 00:18 出处:网络
$(\'#Colors span\').live(\'click\', function(){ var layerFind = \"BACK\"; if ($(this).hasClass(\'.CI_W\')) {
$('#Colors span').live('click', function(){
    var layerFind = "BACK";

    if ($(this).hasClass('.CI_W')) {
        layerFind = "WHITE";
    } else if ($(this).hasClass('.CI_U')) {
        layerFind = "BLUE";
    } else {
        layerFind = "BASE";
    }       

    $("#Base").attr("src", 'Layers/' + layerFind + '.png');
});

I have spans that are icons that represent colors. When a user clicks the icon, the string variable layerFind changes to the appropriate color. This string is then used as the src for an image file. Currently it works for the BASE string value, that is the default when i load th开发者_如何学编程e page, but it doesn't respond to the span clicks.

I'm wondering if a switch statement makes more sense. Later on i will need this script to be able to combine the colors clicked. For example, if i click the white icon and the black icon, the string becomes WB, an abbreviation, and the image file with that name is a gray image. If i click 3 or more, then it uses a secondary default, for example, RAINBOW or something.


dude, your trouble is simple, just remove de $ in the variables inside the ifs

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号