javascript switch(true)

前端 未结 4 1686
别那么骄傲
别那么骄傲 2020-12-01 18:19

Hi i am trying to handle an ajax json response

here is my code

success: function (j) {     
    switch(true)
    {
        case (j.choice1):

                


        
4条回答
  •  孤街浪徒
    2020-12-01 18:30

    In a case like this, a better way to do this is probably something like:

    success: function (j) {
        if(j.choice1 || j.choice2) {
            alert("choice2");
        } else {
            alert("default");
        }
    }
    

提交回复
热议问题