从 .properties 文件中检索错误消息值
我需要从 messages.properties 文件中检索客户端验证的错误消息值并将其显示在页面上。 我使用了
。
<script type="text/javascript">
$(document).ready(function() {
$("#userRegistrationDetails").validate({
rules: {
username: "required",
email: {
required : true,
email : true
},
password: "required",
confpass: {
required :true,
equalTo: "#password"
}
},
messages: {
username: <fmt:message key="uname.prop" />,
email: "Please enter valid email address",
password: "Please enter the password",
confpass: "Please enter the same password"
}
});
});
在我的表单页面中。
我无法使用 label 属性,因为它没有在 spring 中定义。
i need to retrieve error message values for client side validation from messages.properties file and display it on a page.
i used <fmt:message key="uname.prop" />
.
<script type="text/javascript">
$(document).ready(function() {
$("#userRegistrationDetails").validate({
rules: {
username: "required",
email: {
required : true,
email : true
},
password: "required",
confpass: {
required :true,
equalTo: "#password"
}
},
messages: {
username: <fmt:message key="uname.prop" />,
email: "Please enter valid email address",
password: "Please enter the password",
confpass: "Please enter the same password"
}
});
});
in my form page.
i cannot use label attribute since it is not defined in spring.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据我对这个问题的理解,类似于您如何定义用户名消息,为什么不对电子邮件和其他字段执行相同的操作?
From what I understand of the question, similar to how you have defined the message for username, why not do the same for email and other field?
如果需要获取带引号的字符串,则应该用引号将其引起来:
另请注意,由于您正在生成 Javascript 源,因此需要应用适当的转义。
支持 JavaScript 转义,因此使用它比
更有意义。If you need to get quoted string, you should surround it with quotes:
Also note that since you are generating Javascript source, you need to apply the appropriate escaping. Javascript escaping is supported by
<spring:message>
, so it makes sense to use it rather than<fmt:message>
.