[update] My bad.. I didn’t look through the codes properly.. I should have spotted such a small mistake.. What a shame.. I want to delete this question now but to no avail… It would be great if someone can help me delete this. I don’t think such a stupid question deserve to be here.
I have this function:
function magic(a,b,c){
$("#a").on("mouseover", "."+a, function() {
$("#a").css("background", b).css("left", c);
alert(a);
if(a="a"){
b = "b";
c = "10%";
}else{
b = "a";
c = "0%";
}
alert(b);
alert(c);
$("#a").animate({
"top":c
},{
duration:2000,
complete:function(){
$("."+a).addClass(b).removeClass(a);
}
});
});
}
After I execute it twice with different arguments `onLoad`
magic("a","black","10px");
magic("b","red","2px");
the first time mouseover .a,
it should alert “a”, “b” then “10%”,
*and it does.*
However, the second time mouseover the used-to-be-.a (which is .b now),
instead of alert “b”, “a”, “0%”,
*bizarrely, it alert “b”, then “b” again, then “10%”.*
The conclusion I can give is that when going through
if(a=”a”){
b = “b”;
c = “10%”;
}else{
b = “a”;
c = “0%”;
}
it treats a as it has been assigned "a" instead of "b"
but back then it already alert “b”..
(here is a demo: http://jsfiddle.net/UqRdZ/)
I would appreciate if someone can explain it and provide a solution.
The comparison operator is
==, not=So