文本框输入超过一定长度后,弹出提示框,并将光标移动到下一个文本框
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#txt1").keyup(function(){
if ($("#txt1").val().length >= 2){
alert('最多只能输入2个字符');
$('#txt2').focus();
}
});
});
</script>
</head>
<body>
输入框1:<input id="txt1" type="text" /><br>
输入框2:<input id="txt2" type="text" / >
</body>
</html>
<html>
<head></head>
<body>
<input type="text" maxlength="3">
<input type="text" maxlength="3">
<input type="text" maxlength="3">
<script language="javascript">
function Each(arr,fn){for(var i=0,len=arr.length;i<len;i++){fn.call(arr[i],i,arr);};};
(function(inputs){
Each(inputs,function(i){
var _o=this;
this.onkeyup=function(){
if(_o.value.length>=3){
if(inputs[i+1]){
inputs[i+1].focus();
}else{
_o.value=_o.value.slice(0,4);
}
}
}
})
})(document.getElementsByTagName('input'));
</script>
</body>
</html>