新手刚刚接触js 麻烦大神给看看这段代码怎么了

阆苑仙葩 阆苑仙葩 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
下面的这一段代码中为什么用匿名函数的方式就能实现 而定义一个函数后再给添加onkeypress事件就会出现“尚未实现”错误呢。
小弟刚刚开始学习js,思考一上午,实在想不通 求大神解救!

//给每一个input添加输入格式监听
var userName = regForm.userName;

/*userName.onkeypress=function(){
if(!/^\w{2,16}$/.test(userName.value)){
userName.warningNode.style.display="inline";
userName.noticeNode.style.display="inline";
userName.focus();
return;
}else{
userName.warningNode.style.display="none";
userName.noticeNode.style.display="none";
}
}*/
userName.onkeypress=checkFormat(!/^\w{2,16}$/.test(userName.value),userName);

}
//检测输入的格式是否正确
function checkFormat(b,tagName){
if(b){
tagName.warningNode.style.display="inline";
tagName.noticeNode.style.display="inline";
tagName.focus();
return;
}else{
tagName.warningNode.style.display="none";
tagName.noticeNode.style.display="none";
}
}
...全文
评论 8
收藏 已收藏
分享
返回顶部
阆苑仙葩
JavaScript 87,983 成员 224,681 内容