开发者

jQuery if/else Statement Fails

I have this snippet of code that looks for the value in a select box on change and sets a html element with the jQuery .text, the first if statement in the following code seems to work, "Green" but the "Blue" if doesn't, Any ideas why?

$("#firstdrop").change(function() { 
    if ($("#firstdrop").val() == "Gree开发者_StackOverflow社区n") { 
        $('.price-tag').text('Green $5.00');
    } 
    if ($("#firstdrop").val() == "Blue") { 
        $('.price-tag').text('Blue $15.00');
    }        
});

Help appreciated.

Thanks


I make an example for you to get the selected value from select.

<select id="firstdrop">
    <option value="-">-Select-</option>
    <option value="Green">Green</option>
    <option value="Blue" >Blue</option>
</select>

$('#firstdrop').change(function() { 
         var sel_value = $("#firstdrop option:selected").val(); 
         if (sel_value == 'Green') { 
            $('.price-tag').text('Green $5.00');
         } 
         if (sel_value == 'Blue') { 
            $('.price-tag').text('Blue $15.00');
         }
         if( sel_value == '-')
         {
            $('.price-tag').text('0');
         } 
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜