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

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

问题描述



我有这样的代码:

 < input type =textname =company_nameoninvalid =setCustomValidity('Lütfenişaretliyerleri doldurunuz')required /> 

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



我尝试了< input type =textname =company_namesetCustomValidity('Lütfenişaretliyerleri doldurunuz')required />



然后显示英文信息。任何人都知道如何显示其他语言的错误信息?



问候,Zoran

解决方案

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



您有两种可能的方式来设置自定义消息,一种不涉及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屋!

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