input输入后自动跳转

最近做了一个input输入后根据input输入框的长度自动跳转,并且变色的功能,包括适用单独的某个input 或者整个table

 

单独input 的处理

<script type="text/javascript">
function changebg(obj){
		var currObj = document.getElementById( obj.id);
		currObj.style.backgroundColor = 'B0E0E6';
		if (currObj.value.length == currObj.maxLength) {
			currObj.style.backgroundColor = 'white';
			var nextObj = $(obj).parent().next().find("input");
			if (nextObj[0] != null) {
				nextObj[0].focus();
				nextObj[0].style.backgroundColor ='B0E0E6';
				//nextObj.addClass('selected')
			}
		}
    }

   function removeStyle(obj){
        var currObj = document.getElementById(obj.id);
        currObj.style.backgroundColor = '';
    }
</script>	

 

  适合整个table的情况:如下

window.onload = function(){
    var table_1 = document.getElementById("table1");
    var rows_1 = table_1.rows;
    for (var i = 0, leni = rows_1.length; i < leni; i++) {
        var cells_1 = rows_1[i].cells;
        for (var j = 0, lenj = cells_1.length; j < lenj; j++) {
            var input_1 = cells_1[j].children[0];
            input_1.id =  'table_1_'+ i + '_' + j;
            input_1.maxlength = 1;
            var td_c = new changebg(i, leni - 1, j, lenj - 1,'table_1_');
            input_1.onkeyup = td_c.oper;
            input_1.onblur = td_c.oper2;
        }
    }
    
  
function changebg(i, leni, j, lenj,tab_id){
	this.oper = function(){
		var currObj = document.getElementById( tab_id + i + '_' + j);
		currObj.style.backgroundColor = 'B0E0E6';
		if (currObj.value.length == currObj.maxlength) {
			currObj.style.backgroundColor = 'white';
			var nextObj = j < lenj ? document.getElementById(tab_id + i + '_' + (j + 1)) : i < leni ? nextObj = document.getElementById((tab_id + i + 1) + '_0') : null;
			if (nextObj != null) {
				nextObj.focus();
				nextObj.style.backgroundColor = 'B0E0E6';
			}
		}
	}
	
	this.oper2 = function(){
        var currObj = document.getElementById(tab_id + i + '_' + j);
        currObj.style.backgroundColor = '';
    }

}


 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值