这个javascript程序在chrome里能正常运行,在ie里就不行,怎么解决这个兼容性问题!
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>输入框验证</title>
</head>
<body>
输入框1: <input name="textfield1" type="text" id="textfield1" size="6" maxlength="3" /><span ></span><br/>
输入框2: <input name="textfield2" type="text" id="textfield2" size="6" maxlength="3" /><span ></span><br/>
输入框3: <input name="textfield3" type="text" id="textfield3" size="6" maxlength="3" /><span ></span><br/>
输入框3: <input name="textfield4" type="text" id="textfield4" size="6" maxlength="3" /><span ></span><br/>
输入框4: <input name="textfield5" type="text" id="textfield5" size="6" maxlength="3" /><span ></span><br/>
输入框5: <input name="textfield6" type="text" id="textfield6" size="6" maxlength="3" /><span></span><br/>
</body>
<script>
var vary=function () {
for(var i=0;i<6;i++){
var p=document.getElementsByTagName("span")[i];
var obj=document.getElementById('textfield'+(i+1));
if(parseInt(obj.name.substr(-1))==(i+1)){
if(obj.value>100||obj.value<0||!!(obj.value.match(/\D+/))){
p.innerHTML="输入错误";
p.style.position="absolute"
obj.value=""
obj.focus();
}else{
p.innerHTML="";
}
}
}
}
textfield1.onblur=vary;
textfield2.onblur=vary;
textfield3.onblur=vary;
textfield4.onblur=vary;
textfield5.onblur=vary;
textfield6.onblur=vary;
</script>
</html> 展开
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>输入框验证</title>
</head>
<body>
输入框1: <input name="textfield1" type="text" id="textfield1" size="6" maxlength="3" /><span ></span><br/>
输入框2: <input name="textfield2" type="text" id="textfield2" size="6" maxlength="3" /><span ></span><br/>
输入框3: <input name="textfield3" type="text" id="textfield3" size="6" maxlength="3" /><span ></span><br/>
输入框3: <input name="textfield4" type="text" id="textfield4" size="6" maxlength="3" /><span ></span><br/>
输入框4: <input name="textfield5" type="text" id="textfield5" size="6" maxlength="3" /><span ></span><br/>
输入框5: <input name="textfield6" type="text" id="textfield6" size="6" maxlength="3" /><span></span><br/>
</body>
<script>
var vary=function () {
for(var i=0;i<6;i++){
var p=document.getElementsByTagName("span")[i];
var obj=document.getElementById('textfield'+(i+1));
if(parseInt(obj.name.substr(-1))==(i+1)){
if(obj.value>100||obj.value<0||!!(obj.value.match(/\D+/))){
p.innerHTML="输入错误";
p.style.position="absolute"
obj.value=""
obj.focus();
}else{
p.innerHTML="";
}
}
}
}
textfield1.onblur=vary;
textfield2.onblur=vary;
textfield3.onblur=vary;
textfield4.onblur=vary;
textfield5.onblur=vary;
textfield6.onblur=vary;
</script>
</html> 展开
展开全部
经IE6 测试,代码正常。
发现主要是编码问题,请保存为UTF-8.
发现主要是编码问题,请保存为UTF-8.
追问
输入错误!那四个字出来没有?我用的就是utf-8,在ie6,7,8都不行!在ie9可以运行但是“输入错误”这四个字出不来!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询