var cu = $('checkusername');为什么找不到对象呢?
<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 = 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>
错误出现在var cu = $( 'checkusername '); 说是找不到对象 可是明明有 <div> 啊
大家帮帮忙 谢谢 还有
var unlen = username.replace(/[^\x00-\xff]/g, "** ").length;
我想知道这句话是什么意思 谢谢
------解决方案--------------------一般以$(id)函数简化对document.getElementById(id);的调用。