如果变量匹配另一个变量

时间:2012-04-18 03:36:51

标签: javascript jquery

var test = "Example";
var another = "Example";

<div id="whatever">
 Blah
</div>

如果$('#whatever').hide()test匹配,我如何应用another,如果不匹配,我如何应用$('#whatever').css('color','red')

2 个答案:

答案 0 :(得分:3)

简单:

<script type="text/javascript">
    if(test === another){
       $('#whatever').hide();
    }else{
       $('#whatever').css('color','red');
    }
</script>

答案 1 :(得分:2)

使用if statement

if(test == another)
    $('#whatever').hide();
else
    $('#whatever').css('color','red');