js控制表单输入的长度
js控制表单
<body>
<p>在文本框中尝试输入触发函数。</p>
<input type="text" id="myInput" >
<p id="demo"></p>
<script> var a = document.getElementById('myInput'); a.oninput=function(){ if(this.value.length>=5){ alert(1) return this.value = this.value.slice(0,4); } } </script>
还没有评论,来说两句吧...