Test for multiple cases in a switch, like an OR (||)

后端 未结 6 648
暗喜
暗喜 2020-11-28 01:16

How would you use a switch case when you need to test for a or b in the same case?

switch (pagei         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 01:51

    You can use fall-through:

    switch (pageid)
    {
        case "listing-page":
        case "home-page":
            alert("hello");
            break;
        case "details-page":
            alert("goodbye");
            break;
    }
    

提交回复
热议问题