在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ 關(guān)于if else 和 switch優(yōu)化的問(wèn)題

關(guān)于if else 和 switch優(yōu)化的問(wèn)題

let url = location.search
var idbox = {}
if (url === '?news') {
  idbox = {id: 43}
} else if (url === '?character') {
  idbox = {id: 39631}
} else if (url === '?hotspot') {
  idbox = {id: 8928}
} else if (url === '?relation') {
  idbox = {id: 7972}
} else if (url === '?manage') {
  idbox = {id: 444}
} else if (url === '?scholarship') {
  idbox = {id: 3380}
}
  • 如何優(yōu)化以上代碼,用map?
回答
編輯回答
傲嬌范

用switch case吧

2017年1月31日 14:45
編輯回答
心沉
let config = { '?news':{id:43}, '?character':{id: 39631}, ...}
let url = location.search;
let idbox = config[url];
2017年3月23日 22:00