提示缺少对象,可是我觉得没错阿
<HTML>
<HEAD>
<title> Default </title>
</HEAD>
<body>
<form name= "Form1 " id= "Form1 ">
<input name= "txtUser " type= "text " id= "txtUser " onBlur= "checkusername() " />
<div id= "checkusername "> </div>
<input type= "submit " name= "btnSubmit " value= "提 交 " id= "btnSubmit " />
</form>
<script>
var profile_username_toolong = '太长了 ';
var profile_username_tooshort = '太短了 ';
var lastusername = ' ';
function checkusername() {
var username = trim(document.Form1.txtUser.value);
if(username == lastusername ) {
return;
} else {
lastusername = username;
}
var cu = $( 'checkusername ');
var unlen = username.replace(/[^\x00-\xff]/g, "** ").length;
if(unlen < 1 || unlen > 10) {
warning(cu, unlen < 1 ? profile_username_tooshort : profile_username_toolong);
return;
}
}
function warning(obj, msg) {
obj.style.display = ' ';
obj.innerHTML = ' <img src= "images/check_error.gif "> ' + msg;
obj.className = "warning ";
}
</script>
</body>
</HTML>
用鼠标将光标放在textbox上 然后让它失去焦点 这个时候提示缺少对象 这是怎么回事?
还有我想问问 username.replace(/[^\x00-\xff]/g, "** ").length;
这个是什么意思?谢谢
------解决方案--------------------$是正则表表达式的引用很有用代表正则表达式的分组匹配结果。$( 'checkusername ');你应该把它改为RegExp.$(1)或者直接$(1);他代表的是username.replace(/[^\x00-\xff]/g, "** ").中与正则表达式匹配的项。