Use the unary +
operator, which converts its operand into a number.
+ true; // 1
+ false; // 0
Note, of course, that you should still sanitise the data on the server side, because a user can send any data to your sever, no matter what the client-side code says.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…