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

后端 未结 6 644
暗喜
暗喜 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:56

    Use commas to separate case

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

提交回复
热议问题