首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何处理onfocusout,html验证

如何处理onfocusout,html验证
EN

Stack Overflow用户
提问于 2016-09-10 19:20:18
回答 2查看 115关注 0票数 0

在我的代码中,我有以下代码行:

代码语言:javascript
复制
<input type="text" name="fname" id="first" onfocusout="firstNameHandler()">

当我在HTML验证器中运行它时(出于学术目的,它是必需的),它会标记为一个问题。这是我的问题,我需要集中处理,因为我们有文本输入字段,当您写您的名字时,例如john,它会将其转换为John。只有当您不再关注所述文本输入字段时,才会发生这种情况。

因此,怎样才是正确的处理方法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-10 19:50:19

是的,onfocusout不是可移植的,在火狐中也不起作用。对于Internet Explorer:

function isIE () { var myNav = navigator.userAgent.toLowerCase(); return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) : false; }

然后,由于IE9和更高版本支持onblur,但是IE8和更早版本不支持:

if (isIE () && isIE () < 9) { // is IE version less than 9 // insert code to tell the user that they are using a version of // internet explorer that doesn't work with your page // and is outdated.

}

else { // is IE 9 and later or not IE // This means that this will (probably) work // unless the user is using an extremely outdated browser // or one that doesn't support JavaScript.

}

票数 1
EN

Stack Overflow用户

发布于 2016-09-10 19:27:48

嗯,找到了使用onblur而不是onfocusout的解决方案,然而,我想知道的是IE的方法是什么,如果我没有弄错的话,IE在每一种可能的形式上都是特殊的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39429755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档