Specify case statement in jQuery
How can i convert this code to jquery
var tmp = "";开发者_如何学Python
for (var x in y) {
switch (x) {
case "abc":
document.getElementById("apple").innerHTML = "A";
break;
case "xyz":
document.getElementById("banana").innerHTML = "X";
break;
}
}
I assume variable x is an array? This would be an approach too:
$(x).each(function(key, value) {
switch(value) {
case "abc":
$("#apple").html("A");
break;
case "xyz":
$("#banana").html("X");
}
});
It would be helpful to have a little more detail, but how about this
var tmp = "";
for (var x in y) {
switch (x) {
case "abc":
$("#apple").html("A");
break;
case "xyz":
$("#banana").html("X");
}
}
精彩评论