更改 html5 联系表单中必填字段中错误消息的语言 [英] changing the language of error message in required field in html5 contact form

查看:33
本文介绍了更改 html5 联系表单中必填字段中错误消息的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改 html5 表单字段中错误消息的语言.

I am trying to change the language of the error message in the html5 form field.

我有这个代码:

<input type="text" name="company_name"  oninvalid="setCustomValidity('Lütfen işaretli yerleri doldurunuz')" required /> 

但是在提交时,即使字段不为空,我仍然收到错误消息.

but on submit, even the field is not blank, I still get the error message.

我尝试使用 <input type="text" name="company_name" setCustomValidity('Lütfen işaretli yerleri doldurunuz') required/>

但随后显示英文消息.有人知道如何以其他语言显示错误消息吗?

but then the english message is displayed. Anyone know how can I display the error message on other language?

问候卓然

推荐答案

setCustomValidity 的目的不仅仅是设置验证消息,它本身将字段标记为无效的.它允许您编写本机不支持的自定义验证检查.

setCustomValidity's purpose is not just to set the validation message, it itself marks the field as invalid. It allows you to write custom validation checks which aren't natively supported.

您有两种可能的方法来设置自定义消息,一种不涉及 Javascript 的简单方法,另一种涉及 Javascript.

You have two possible ways to set a custom message, an easy one that does not involve Javascript and one that does.

最简单的方法是在 input 元素上简单地使用 title 属性 - 其内容与标准浏览器消息一起显示.

The easiest way is to simply use the title attribute on the input element - its content is displayed together with the standard browser message.

<input type="text" required title="Lütfen işaretli yerleri doldurunuz" />

如果您只想显示自定义消息,则需要一些 Javascript.我在这个小提琴中为你提供了这两个例子.

If you want only your custom message to be displayed, a bit of Javascript is required. I have provided both examples for you in this fiddle.

这篇关于更改 html5 联系表单中必填字段中错误消息的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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