js 每4位一格最终完美绝不修改版



function setPos(num)
{
var e =document.getElementById("twocodequery");
var r =e.createTextRange();
r.moveStart('character',num);
r.collapse(true);
r.select();
}


function setPos_a(num)
{
var e =document.getElementById("old_order");
var r =e.createTextRange();
r.moveStart('character',num);
r.collapse(true);
r.select();
}




function twocodequery_edit() 
{
	var c = event.keyCode;
	if(event.keyCode== 37||event.keyCode== 39)
		return true;


	var obj = document.getElementById("twocodequery");
	var s=document.selection.createRange();
	s.setEndPoint("StartToStart",obj.createTextRange())
	var pos = s.text.length;


	var str = document.getElementById("twocodequery").value; 
	document.getElementById("twocodequery").value =str.replace(/\s/g,'').replace(/([A-Za-z0-9#]{4})/g,"$1 ");   
	if(str.length == 5||str.length == 10||str.length == 15||str.length == 20||str.length == 25||str.length == 30)
	{
		if((str.length -pos) == 1)
		{
			setPos(pos);
		}
	}


	if(pos<str.length)
	{ 
		if(pos == 5||pos == 10||pos == 15||pos== 20||pos == 25||pos == 30)
		{
			if(event.keyCode!= 8)
				pos += 1;
		}
		setPos(pos);
	}else
	{
		if((pos+1)% 5== 0)
		{
			setPos(pos);
		}
	}
 } 

你可能感兴趣的:(c,function,character)