如何检查< div>与不引人注目的javascript有效 [英] How to check if a <div> is valid with unobtrusive javascript

查看:83
本文介绍了如何检查< div>与不引人注目的javascript有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在客户端加载div的表格.我有带有所有验证属性的硬编码文本框控件,类似于从服务器加载时呈现的内容. div内有一个提交按钮,但是当我单击提交"时,将显示表单上的所有验证消息.我只需要显示div元素验证消息.在ajax模式下的Telerik Grid控件执行类似的操作,即在客户端添加带有硬编码验证属性的文本框,但它仅针对网格而不是整个表单触发验证.我想我在这里缺少什么.

I have a form which loads a div on client side. I have hard coded textbox controls with all validation attributes, similar to what it renders when loaded from server. Inside the div there is submit button, but when I click on submit all validations messages on the form are displayed. I just need only the div elements validation messages to be shown. Telerik Grid control in ajax mode, does similar thing, i.e., appends textboxes with hardcoded validation attributes on client side, but it manages to fire validations only for the grid not entire form. I think I am missing something here.

$('#div').valid() --> doesn't work
$('#form').valid() --> works

推荐答案

将div添加到DOM后,您需要解析包含表单的验证规则:

You need to parse the validation rules of the containing form once you add the div to the DOM:

var form = $('#div').closest('form');
form.removeData('validator');
form.removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse(form);

,这是一个实时演示.

这篇关于如何检查< div>与不引人注目的javascript有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆