我想寫一個名爲input()(執行輸入驗證)的javascript函數,它將包含3個參數 - 參數是message,min和max。javascript函數輸入驗證
我有麻煩帶來/寫作的功能作爲一個整體,設法解決了一些功能,雖然 - 任何幫助表示讚賞!
到目前爲止的代碼:
// declare variables
var min = 5
var max = 20
var message = 'input must be between 5 and 20';
// get user input
input = parseInt(prompt(message));
// check range
while(isNaN(input) || input<min || input>max) {
alert('input was invalid');
input = parseInt(prompt(message));
}
// output validation
alert('input was accepted');
(從http://jsfiddle.net/AnJym/2/)
@sushilbharwani http://jsfiddle.net/AnJym/2/ – geef