编程语言
首页 > 编程语言> > html+javaScript只能输入0-100正整数

html+javaScript只能输入0-100正整数

作者:互联网

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	  <head>
		<script>
			//当单击文本框中时选中所有文本
			function selectText(selectAll) {
				selectAll.select();//选中框中的所有文本;
			}
            只能输入0-100
            function numberTesting(id,value) {
				if(id.name=="Opacity"){
					var reg =/^0+(?=\d)|\D|^[2-9]0(?=[0-9])|^[1-9]+?(?=[1-9][0-9])|^10(?=[1-9])/;//只能输入0-100
          		    value=value.replace(reg,'');
          		    console.log("1:"+value); 
					id.value=value;
				}
            }
		</script>
	  </head>

	  <body style="background-color: #a2a1a3;" >
		  <form>
                <input type="text" id="OpacityID" name="Opacity" class="textSize"  value='100' onclick="selectText(this)"  maxlength="3"  onkeyup="numberTesting(this,this.value)">
          </form>

	  </body>
</html>

 

标签:selectAll,function,javaScript,value,reg,html,100,id
来源: https://blog.csdn.net/cyj51060/article/details/112060796