如何更改电子邮件的HTML5模式错误消息 [英] How to change html5 pattern error messages for email

查看:121
本文介绍了如何更改电子邮件的HTML5模式错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Html5必需属性通常会添加错误消息请填写此字段".并且可以使用以下代码轻松更改

Html5 required attribute adds normally the error message "Please fill out this field." and it can easily be changed with the following code

oninvalid="setCustomValidity('Custom text in another language..')" 
oninput="setCustomValidity('')"

但是,我注意到当我使用类型为email的输入时,我仍然收到诸如请在'@之后输入一个部分"之类的消息.和请在电子邮件地址中包含'@'",如何更改它们?

However, I have noticed that when I use inputs with type email I still get messages such as "Please enter a part following '@." and "Please include an '@' in the email address", how can I change them?

推荐答案

自定义错误消息来自元素的标题,或者使用setCustomValidity,如您所说. 但是诸如请在电子邮件地址中包含'@'"之类的消息来自type="email"属性.例如,当存在required属性时,也会出现类似的错误消息.因此,这些消息来自浏览器,并且将以用户的浏览器语言显示.我不会对此太担心,因为浏览器已经是用户可以理解的语言,并且因为它们是浏览器的本机,所以用户会习惯于这些标准错误消息.

The custom error message comes from the element's title, or by using setCustomValidity, as you said. But message like "Please include an '@' in the email address" come from the type="email" attribute. There are similar error messages when there is a required attribute, for example. So these messages come from the browser, and will be in the user's browser language. I wouldn't worry too much about this, as the browser will already be in a language the user understands, and as they are native to the browser, users will get used to these standard error messages.

这篇关于如何更改电子邮件的HTML5模式错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆