<html>
<head>
<title>只能输入正整数</title>
</head>
<body>
兑换数量:<input type="text" ID="txtNumber" Width="50px" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"
onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}" />
<input type="button" ID="btn1" value=" 兑 换 " OnClick='return confirm("确定兑换?");' />
</body>
</html>有趣的 验证JS只能输入正整数
本文介绍了一个简单的HTML输入框实例,通过JavaScript实现在文本框中只能输入正整数的功能。该实例适用于兑换数量等场景,确保用户输入的数据符合预期格式。


被折叠的 条评论
为什么被折叠?



