开发者

Conditional always evaluates as if true

I wrote this post function in my jquery plugin and then faced to a strange problem .

Is the condition statement in开发者_StackOverflow this jquery code correct ?

if(info = "enabled"){
    $("#mod"+mod_id+" > img.status").attr("src","images/active.gif");
}else if(info = "disabled"){
    $("#mod"+mod_id+" > img.status").attr("src","images/inactive.gif");
}else{
    $("#waiting"+mod_id).delay(2000).html(\'<img src="images/error.png" />\'+data);
}

Problem is that it only returns the value enabled and can't handle the "disabled" value


this is assignment

jsfiddle

http://jsfiddle.net/mbbjh/

if(info = "enabled"){ //wrong

this is comparision

if(info == "enabled"){

try trim also if you have any spaces coming

if($.trim(info).toLowerCase()=="enabled") {


you must use == (equality) or === (Identity) to compare expressions instead of =.

I'd recommend using === this prevents type conversion and returns true if a value and a type of expressions are both same.


==, not =

simple as that..........

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜