jQuery验证插件:使用来自xml文件的自定义错误消息 [英] jQuery validation plugin: using custom error messages from xml-file
本文介绍了jQuery验证插件:使用来自xml文件的自定义错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我试图将错误消息外包到xml文件中,因此更改它们或为新元素添加一些新消息变得更加容易.
Hey I tried to outsource my error messages into a xml-File, so changing them or adding some new messages for new elements gets easier.
我的xml文件如下:
<messages>
<element>
<name>name</name>
<pflicht>Text bei Pflicht.</pflicht>
<format>email</format>
<formattext>Text bei falschem Format</formattext>
</element>
<element>
<name>postleitzahl</name>
<pflicht>Required</pflicht>
<format>plz</format>
<formattext>Bitte Postleitzahl angeben.</formattext>
</element>
</messages>
然后应为每个element-tag编写结果函数,如下所示: 例如:
And the resulting function should be written for each element-tag and look like this: For example:
jQuery(".validation").rules("add",{
messages:{
name :{
required: "Text bei Pflicht",
email: "Text bei falschem Format"
}
postleitzahl:{
required: "Required.",
plz: "Bitte Postleitzahl angeben."
}
});
我该如何实现?
谢谢.
推荐答案
var myXML;
$.ajax({
type: "GET",
url: "message.xml",
dataType: "xml",
success: function(xml) {
alert($(xml).find('element'));
}
});
var nm = returnValue("name");
var frm = returnValue("format");
jQuery(".validation").rules("add",{
messages:{
nm:{
required: returnValue("pflicht"),
frm : returnValue("formattext")
}
}
})
function returnValue(_tag){
return myXML.find(_tag).text();
}
这篇关于jQuery验证插件:使用来自xml文件的自定义错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文