开发者

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");
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜