【发布时间】:2016-01-15 13:31:51
【问题描述】:
我不想显示验证消息,而是想将验证消息附加到控件的标题属性,我已经完成了,但是工具提示没有显示标题属性,并且验证失败时也没有出现红色边框。
这里我附上了小示例代码,我遵循它来将验证消息附加到控件属性。
$("span[class='field-validation-error']").each(function () {
$(this).addClass("hidden");//Add class hidden to hide @@Html.ValidationMessageFor(model => model.xyz) if using bootstrap , else use css
var inputID = $(this).attr("data-valmsg-for");//get the id of the input field for which this validation prompted
var validationMessage = $(this).html();//Get validation message for input filed which is prompted
//$("#" + inputID).tooltip({ 'trigger': 'hover', 'title': validationMessage });//Trigger the tooltip now, if using bootstrap.
//******OR*******
$("#" + inputID).attr("title",validationMessage);
});
}
return false;
});
我的完整 jquery 和 mvc 代码在 dotnet fiddle 中,其链接是 https://dotnetfiddle.net/30YQEX
所以请有人检查代码并与我讨论我在那里做错了什么?
1) 为什么将鼠标悬停在导致验证失败的控件上时没有出现工具提示?
2) 为什么验证失败时没有出现红色边框?
谢谢
【问题讨论】:
标签: jquery asp.net-mvc validation