-
[上海|结业弟子]JS-任我行0
最简单的,就是使用if else来分配人数,
//声明杀手变量和平民变量
var killer;
var civilian;
//获取杀手数量和平民数量
function makeId() {
getValue();
if (inputNumber > 18 || inputNumber < 4) {
killer = " ";
civilian = " ";
}
if (players == undefined) {
return;
}
if (players >= 4 && players < 6) {
killer = 1;
civilian = players - killer;
} else if (players >= 6 && players < 9) {
killer = 2;
civilian = players - killer;
} else if (players >= 9 && players < 12) {
killer = 3;
civilian = players - killer;
} else if (players >= 12 && players < 16) {
killer = 4;
civilian = players - killer;
} else {
killer = 5;
civilian = players - killer;
}
}
监听是用addEventListener去监听input输入框的内容变更后,分配人数以及数组乱序
inputNumber >= 4 && inputNumber <= 18这个可以用&&卸载一起
编辑于2018-11-25 -
[成都|]JS-0编辑于2019-01-26
- 去第 页