<input id="discount" maxlength='3' onkeyup="myFunction(this.value)" /> function myFunction(nubmer) { if (isNaN(nubmer) || nubmer <= 0 || nubmer >= 101 || !(/^\d+$/.test(nubmer))) { { $.messager.alert('提示','请输入正确的数值,只允许输入小于等于100的正整数!'); document.getElementById("discount").value = ""; return false; } } }