开发者

Conditional always evaluates as if true

开发者 https://www.devze.com 2023-03-03 14:46 出处:网络
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 ?

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

精彩评论

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

关注公众号