This article mainly introduces JQuery to determine positive integers. Detailed code is attached for everyone to see the specific method. Friends in need can refer to it. I hope it can help everyone.
var totalPage = document.getElementById("totalPage").value.trim();//获取总页 var reg=/^[1-9]\d*$/; //由 1-9开头 的正则表达式 //先判断是否为整数 在判断 是否在 1-总页 整数范围之内 if(reg.test(searchBox)){ if(parseInt(searchBox) > 0 && parseInt(searchBox) <= totalPage){ alert(searchBox); }else{ alert("输入的页码超出指定范围!!!"); document.getElementById("searchBox").value = ""; //清空 return; } }else{ alert("请输入合法的整数页码!!"); document.getElementById("searchBox").value = ""; //清空 return; }
Related recommendations:
php function code to judge positive integers
Summary of various methods for judging integers in JavaScript_javascript skills
The above is the detailed content of Summary of JQuery's method of judging positive integers. For more information, please follow other related articles on the PHP Chinese website!