主题:javascript中类型不匹配的问题
我做了一个无刷新验证用户名的页面,运行正常,但是在tt浏览器下,提示有错误:
行: 126
字符: 3
错误: 类型不匹配
代码: 0
URL: http://localhost/test.html
代码如下(红色是出错部分):
<script type="text/javascript" language="javascript">
var profile_username_toolong = '对不起,您的用户名超过 15 个字符,请输入一个较短的用户名。';
var profile_username_tooshort = '对不起,您输入的用户名小于4个字符, 请输入一个较长的用户名。';
var profile_username_illegal = '用户名包含敏感字符或被系统屏蔽,注意用户名只能使用英文和数字,请重新填写。';
var profile_username_offlien = '无法连接到数据库,请刷新页面后从新填写。';
var profile_username_used = '用户名已经被使用,请更换。';
var lastseccode = lastsecanswer = lastusername = lastpassword = lastemail = '';
function trim(str) {
return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
}
function warning(obj, msg) {
if((ton = obj.id.substr(5, obj.id.length)) != 'password2') {
document.getElementById(ton).select();
}
obj.style.display = '';
obj.innerHTML = '<img src="images/check_error.gif" width="13" height="13"> '+ msg;
obj.className = "warning";
}
function right(obj, msg) {
if((ton = obj.id.substr(5, obj.id.length)) != 'password2') {
document.getElementById(ton).select();
}
obj.style.display = '';
obj.innerHTML = '<img src="images/blue/check_right.gif" width="13" height="13">';
obj.className = "right";
}
function chkacc(){
var username = document.getElementById("username").value;
username = trim(username);
alert("checkusername.asp?username="+username);
}
function checkunindb(username,cu){
var getrs= new ActiveXObject("Microsoft.XMLHTTP");
getrs.open("post","checkusername.asp?username="+username,false);
getrs.send();
getrs.onreadystatechange=statechange(getrs)
}
function statechange(getrs,cu){
if (getrs.readyState == 4){
if(getrs.responseText==""){warning(cu, profile_username_offlien);alert("empty");return;}
else if(trim(getrs.responseText)=="no"){warning(cu, profile_username_used);alert(getrs.responseText);return;}
else if(trim(getrs.responseText)=="yes"){right(cu, 'ok');alert(getrs.responseText);return;}
}else{alert("getrs.readyState"+getrs.readyState);alert("getrs.status"+getrs.status);}}
function checkusername() {
var username = document.getElementById("username").value;
username = trim(username);
if(username == lastusername) {
return;
} else {
lastusername = username;
}
var cu = document.getElementById("checkusername");
var unlen = username.replace(/[^\x00-\xff]/g, "**").length;
if (/^[a-zA-Z0-9_]+$/.test(username)){
if(unlen < 4 || unlen > 15) {
warning(cu, unlen < 4 ? profile_username_tooshort : profile_username_toolong);
return;
}else{
var getrs= new ActiveXObject("Microsoft.XMLHTTP");
getrs.open("post","checkusername.asp?username="+username,false);
getrs.send();
[color=FF0000]getrs.onreadystatechange=statechange(getrs,cu)[/color]
}
}else{
warning(cu, profile_username_illegal);
return;
}
}
</script>
</head>
<body>
<form name="reg" method="post" action="freg.asp">
<table cellspacing="0" cellpadding="4" width="598" align="center">
<!--DWLayoutTable-->
<tr>
<td height="32" colspan="2" background="images\uph.GIF" class="color1">个人用户注册界面 </td>
</tr>
<tr>
<td bgcolor="#D2DBE2" colspan="2" class="color1"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td width="70" class="text1" >用户名:</td>
<td width="482" class="text1" valign="middle"><input type="text" name="username" size="25" maxlength="15" id="username" class="input" onBlur="checkusername()">
<span id="checkusername"></span></td>
</tr>
</table>
</form>
</body>
</html>
页面运行正常,功能都完好,但是不知道这个错误是怎么回事,心里不踏实,第一次接触javascript和无刷新,大家帮忙看看,谢谢了。
行: 126
字符: 3
错误: 类型不匹配
代码: 0
URL: http://localhost/test.html
代码如下(红色是出错部分):
<script type="text/javascript" language="javascript">
var profile_username_toolong = '对不起,您的用户名超过 15 个字符,请输入一个较短的用户名。';
var profile_username_tooshort = '对不起,您输入的用户名小于4个字符, 请输入一个较长的用户名。';
var profile_username_illegal = '用户名包含敏感字符或被系统屏蔽,注意用户名只能使用英文和数字,请重新填写。';
var profile_username_offlien = '无法连接到数据库,请刷新页面后从新填写。';
var profile_username_used = '用户名已经被使用,请更换。';
var lastseccode = lastsecanswer = lastusername = lastpassword = lastemail = '';
function trim(str) {
return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
}
function warning(obj, msg) {
if((ton = obj.id.substr(5, obj.id.length)) != 'password2') {
document.getElementById(ton).select();
}
obj.style.display = '';
obj.innerHTML = '<img src="images/check_error.gif" width="13" height="13"> '+ msg;
obj.className = "warning";
}
function right(obj, msg) {
if((ton = obj.id.substr(5, obj.id.length)) != 'password2') {
document.getElementById(ton).select();
}
obj.style.display = '';
obj.innerHTML = '<img src="images/blue/check_right.gif" width="13" height="13">';
obj.className = "right";
}
function chkacc(){
var username = document.getElementById("username").value;
username = trim(username);
alert("checkusername.asp?username="+username);
}
function checkunindb(username,cu){
var getrs= new ActiveXObject("Microsoft.XMLHTTP");
getrs.open("post","checkusername.asp?username="+username,false);
getrs.send();
getrs.onreadystatechange=statechange(getrs)
}
function statechange(getrs,cu){
if (getrs.readyState == 4){
if(getrs.responseText==""){warning(cu, profile_username_offlien);alert("empty");return;}
else if(trim(getrs.responseText)=="no"){warning(cu, profile_username_used);alert(getrs.responseText);return;}
else if(trim(getrs.responseText)=="yes"){right(cu, 'ok');alert(getrs.responseText);return;}
}else{alert("getrs.readyState"+getrs.readyState);alert("getrs.status"+getrs.status);}}
function checkusername() {
var username = document.getElementById("username").value;
username = trim(username);
if(username == lastusername) {
return;
} else {
lastusername = username;
}
var cu = document.getElementById("checkusername");
var unlen = username.replace(/[^\x00-\xff]/g, "**").length;
if (/^[a-zA-Z0-9_]+$/.test(username)){
if(unlen < 4 || unlen > 15) {
warning(cu, unlen < 4 ? profile_username_tooshort : profile_username_toolong);
return;
}else{
var getrs= new ActiveXObject("Microsoft.XMLHTTP");
getrs.open("post","checkusername.asp?username="+username,false);
getrs.send();
[color=FF0000]getrs.onreadystatechange=statechange(getrs,cu)[/color]
}
}else{
warning(cu, profile_username_illegal);
return;
}
}
</script>
</head>
<body>
<form name="reg" method="post" action="freg.asp">
<table cellspacing="0" cellpadding="4" width="598" align="center">
<!--DWLayoutTable-->
<tr>
<td height="32" colspan="2" background="images\uph.GIF" class="color1">个人用户注册界面 </td>
</tr>
<tr>
<td bgcolor="#D2DBE2" colspan="2" class="color1"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td width="70" class="text1" >用户名:</td>
<td width="482" class="text1" valign="middle"><input type="text" name="username" size="25" maxlength="15" id="username" class="input" onBlur="checkusername()">
<span id="checkusername"></span></td>
</tr>
</table>
</form>
</body>
</html>
页面运行正常,功能都完好,但是不知道这个错误是怎么回事,心里不踏实,第一次接触javascript和无刷新,大家帮忙看看,谢谢了。