ASP.NET MVC验证使用qTip jQuery插件
发布时间:2020-12-16 04:37:02 所属栏目:asp.Net 来源:网络整理
导读:我正在使用找到的解决方案 here在使用qTip jQuery插件的工具提示中显示客户端验证错误.此解决方案非常适合客户端验证,但我希望能够以相同的方式显示服务器端验证错误.有谁知道如何利用qTip在工具提示中显示服务器端验证错误? 谢谢 解决方法 如果存在服务器
我正在使用找到的解决方案
here在使用qTip jQuery插件的工具提示中显示客户端验证错误.此解决方案非常适合客户端验证,但我希望能够以相同的方式显示服务器端验证错误.有谁知道如何利用qTip在工具提示中显示服务器端验证错误?
谢谢 解决方法
如果存在服务器端验证错误,当页面加载时会有一个带有“field-validation-error”类的span元素,因此我们可以简单地循环遍历该类的所有元素,提取内容或错误消息,并将其显示在工具提示中.
$(document).ready(function () { // Run this function for all validation error messages $('.field-validation-error').each(function () { // Get the name of the element the error message is intended for // Note: ASP.NET MVC replaces the '[',']',and '.' characters with an // underscore but the data-valmsg-for value will have the original characters var inputElem = '#' + $(this).attr('data-valmsg-for').replace('.','_').replace('[','_').replace(']','_'); var corners = ['left center','right center']; var flipIt = $(inputElem).parents('span.right').length > 0; // Hide the default validation error $(this).addClass('Hidden'); // Show the validation error using qTip $(inputElem).filter(':not(.valid)').qtip({ content: { text: $(this).text() },// Set the content to be the error message position: { my: corners[flipIt ? 0 : 1],at: corners[flipIt ? 1 : 0],viewport: $(window) },show: { ready: true },hide: false,style: { classes: 'ui-tooltip-red' } }); }); }); 这是一个blog post,详细解释了如何做到这一点. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 使用ASP.NET(C#)在不使用QueryString的情况下将变量从页面传
- ASP.NET内置用户配置文件与旧stile用户类/表
- asp.net – 在维护期间重定向站点访问者
- asp.net-mvc – ASP.NET MVC 1.0 – 字典的模型绑定器
- 经典ASP和UTF-8
- asp.net-web-api – 如何记录webapi中控制器中执行的操作方
- 扩展UltraGrid控件实现对所有数据行的全选功能[Source Code
- Asp.Net会话在ashx文件中为null
- asp.net – asp .net mvc OnResultExecuting modify filter
- asp.net-mvc – MVC:传入字典的模型项是X类型,但是这个字典
推荐文章
站长推荐
- asp.net – 是否可以有条件地包含CSS?
- asp.net-mvc – MVC“添加控制器”是“无法检索元
- asp.net-mvc – 如何使用Html.DropDownList为默认
- asp.net-mvc-3 – 如何从部分视图将JavaScript渲
- asp.net-mvc – ASP.NET Webforms或ASP.NET MVC中
- asp.net-mvc – 如何使用html帮助器在asp.net mv
- asp.net – AspNetSession布局渲染器不工作
- ASP.NET 路由实现去除aspx后缀
- Forms身份验证应用程序中的ASP.NET Web服务
- asp.net-mvc – AngularJS无法在发布模式下工作(
热点阅读