html,js验证表单并限制输入长度代码
html,js验证表单并限制输入长度代码
<input id="username" type="text" maxlength=20 />
同时在页面的script部分加入:
<script type="text/javascript">
$(document).ready(function(){
$("input#username").keyup(function(){
if($("input#username").val().length>=20){
alert('*多只能输入20个字符')///这里换成你要显示的提示语即可!
}
});
});
</script>
