显示星号与NotEmpty Fluentvalidation [英] Show asterisk with NotEmpty Fluentvalidation
本文介绍了显示星号与NotEmpty Fluentvalidation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要Asp.Net MVC 4 Web页面上显示标签
用星号时,拥有房产的 NotEmpty
规则
I want to show on Asp.Net MVC 4 web page a label
with asterisk when property have NotEmpty
rule.
推荐答案
就在这个函数添加到您的公共脚本功能和负载运行
Just add this function to your common script functions and run on load
$(document).ready(function(){
setRequired();
});
function setRequired() {
var $form = $('form');
$('form').find("[data-val-required]").each(function (index) {
var $input = $(this);
var requiredAsterisk = "<span class=\"required\">*</span>";
var id = $input.attr('id');
var $label = $form.find("label[for='" + id + "']");
if ($label.length > 0) {
var html = $label.html() + "";
if (html.indexOf(requiredAsterisk) <= 0) $label.html(html + requiredAsterisk);
}
});
};
这确实是什么,它增加了星号,以必需的字段标签。您可以轻松地将它更改为旁边将其添加到输入字段。
What this does it , it adds asterisk to labels of required fields. You can easily change it to add it right next to input fields.
另外需要注意的是我使用 CSS类=所需
,所以记得要添加颜色:红色
的这个CSS类。
Another thing to note is I use css class = required
, so remember to add the color:red
for this css class.
这篇关于显示星号与NotEmpty Fluentvalidation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文