如果有N個問題,那么構(gòu)建一個N維數(shù)組,通過查表計算arr[select_1][select_2][select_3][]...[select_n]來獲得結(jié)果。比如你的題目有2個問題,那么就構(gòu)建一個二維數(shù)組,預先存儲一個表。賦值階段可以區(qū)分一下數(shù)組是不是足夠酥松如果酥松的話就把有值的地方賦好就行了:vararr=Array(2);arr[0]=Array(10);arr[1]=Array(10);arr[0][0]="123"arr[3][4]="123123"arr[5][10]="21312"functionshowAnswerForSelects(){returnarr[arguments[0]][arguments[1]];}showAnswerForSelects(3,4)->"123123"showAnswerForSelects(7,5)->undefined或者數(shù)據(jù)比較酥松,還可以構(gòu)建一個switch邏輯,像這樣:functionshowAnswerForSelects(){varstr=arguments[0]+"-"+arguments[1];switch(str){case"0-1":return"123";case"3-4":return"123123";case"5-10":return"21312";default:returnnull;}}調(diào)用還是一樣的方式。如果比較密,那么就用字面量的方式直接賦值吧:vararr=[["123123","12312","123123"..."234134"],["123123","12312","123123"..."234134"],["123123","12312","123123"..."234134"],["123123","12312","123123"..."234134"],["123123","12312","123123"..."234134"],["123123","12312","123123"..."234134"],["123123","12312","123123"..."234134"],["123123","12312","123123"..."234134"],["123123","12312","123123"..."234134"],["123123","12312","123123"..."234134"]];functionshowAnswerForSelects(){returnarr[arguments[0]][arguments[1]];}嫌不好索引還可以用@kikong的對象字面量的方式來做。