图像改变即使它是无关的

时间:2015-09-09 08:06:38

标签: javascript php jquery

我有这个脚本可以检测cookie并根据所选语言更改照片。当我尝试单击左键时,图像会正确更改,但是当我单击右键时,它会更改左键照片。这是我的代码: -

HTML

<div id="slide_left" class="slide_left_close srl_menu">
<?php 
     if ($_COOKIE['language'] == 'indo') {
        echo '<button id="button_left" class="button-left" value="indo"><img id="bsright" src="'.$imgUrl.'images/indo/slide-left-button.png"/></button>';
     } else {
        echo '<button id="button_left" class="button-left" value="en"><img id="bsright" src="'.$imgUrl.'images/en/slide-left-button.png"/></button>';   
    }
?>
</div>

<div id="slide_right" class="slide_right_close srl_menu">
<?php 
    if ($_COOKIE['language'] == 'indo') {
        echo '<button id="button_right" class="button" value="indo"><img id="bsright" src="'.$imgUrl.'images/indo/slide-right-button.png"/></button>';
    } else {
        echo '<button id="button_right" class="button" value="en"><img id="bsright" src="'.$imgUrl.'images/en/slide-right-button.png"/></button>';
    }
?>
</div>

JS

$(document).ready( function(){

    /************************/
    /* SLIDE LEFT BUTTON */
    /***************************************/

    $("#button_left").on( "click", function(){
        var btnLeftLang = $(this).attr("value");
        /*Opens and closes the menu*/
        $("#slide_left").toggleClass("slide_left_open");
        if($("#slide_left").hasClass("slide_left_open")){
            /*If the menu is open, then:*/
            /*Change the menu button icon*/
            $("#bsleft").attr('src',imgPath+'images/'+btnLeftLang+'/slide-left-button.png');
         }else{
            /*If the menu is closed, change to the original button icon*/
            $("#bsleft").attr('src',imgPath+'images/'+btnLeftLang+'/slide-left-button.png');
         }
     });

    /************************/
    /* SLIDE RIGHT BUTTON */
    /***************************************/

    $("#button_right").on( "click", function(){
        var btnLang = $(this).attr("value");
        /*Opens and closes the menu*/
        $("#slide_right").toggleClass("slide_right_open");
        if($("#slide_right").hasClass("slide_right_open")){
            /*Change the menu button icon*/ 
            $("#bsright").attr('src',imgPath+'images/'+btnLang+'/slide-right-button.png');
        }else{
            /*If the menu is closed, change to the original button icon*/
            $("#bsright").attr('src',imgPath+'images/'+btnLang+'/slide-right-button.png');
        }
    });
});

0 个答案:

没有答案