在html5联系表单中在必填字段中更改错误消息的语言 [英] changing the language of error message in required field in html5 contact form
问题描述
我有这样的代码:
< input type =textname =company_nameoninvalid =setCustomValidity('Lütfenişaretliyerleri doldurunuz')required />
但是在提交时,即使字段不是空白,我仍然会收到错误消息。
我尝试了< input type =textname =company_namesetCustomValidity('Lütfenişaretliyerleri doldurunuz')required />
然后显示英文信息。任何人都知道如何显示其他语言的错误信息?
问候,Zoran
您有两种可能的方式来设置自定义消息,一种不涉及Javascript且不涉及Javascript的方法。
最简单的方法是简单地在输入元素上使用 title 属性 - 其内容与标准浏览器消息一起显示。
< input type =textrequired title =Lütfenişaretliyerleri doldurunuz/>
如果您只想显示自定义消息,则需要一点Javascript。我在这个小提琴上为您提供了两个例子。
I am trying to change the language of the error message in the html5 form field.
I have this code:
<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.
I tried with <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?
Regards,Zoran
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.
You have two possible ways to set a custom message, an easy one that does not involve Javascript and one that does.
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" />
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屋!