str11=str.substring(0,2)
strSep=":"
str00=str.substring(2,str.length)
strNew=str11+strSep+str00
alert(strNew)
-->
</script>
修改后<script>
function ch_n(){
var obj=document.getElementById("txt")
var va=obj.value
if(va!=""){
var v=va.split(":")
var str=""
for(var i=0i<v.lengthi++){
if(v[0]!=""){
if(v[i].length>2){
var v1=v[i].split("")
for(var j=1j<=v1.lengthj++){
if(j%2==0){
str+=v1[j-2]+""+v1[j-1]+":"
}
}
if(v1.length%2!=0)
str+=v1[v1.length-1]
}else{
if(v[i]!="" &&v[i].length==2)
str+=v[i]+":"
else
str+=v[i]
}
}
}
obj.value=str
}
}
</script>
<body><input name="txt" type="text" id="txt" size="60" onKeyUp="ch_n()"></body>
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
<script>
var tt=null
function ch_n(){
var obj=document.getElementById("txt")
var v=obj.value.split(":")
if(v.length==1){
if(v[0].length==2){
obj.value+=":"
}
}else{
if(v[v.length-1].length==2){
obj.value+=":"
}
}
}
</script>
<body><input name="txt" type="text" id="txt" size="60" onFocus="tt=setInterval(ch_n,50)" onBlur="clearInterval(tt)"></body>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)