jQuery的克隆验证删除错误类 [英] jquery clone validation removing error class

查看:101
本文介绍了jQuery的克隆验证删除错误类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在克隆具有一组表单字段的div标签.我可以使用以下代码维护唯一的ID和名称.

I am cloning a div tag that has set of form fields. I am able to maintain unique ID's and names with below code.

问题:克隆之前(单击添加按钮)如果单击提交,则会执行验证并显示一些错误消息.如果我现在单击添加按钮(克隆),它将错误标签标记带到新克隆的部分.因此,如果我从第一部分的必填字段中删除了数据,则原始部分和克隆部分中都会显示错误消息.

Issue: Before cloning (Clicking add button) If I click submit, validation is executed and put some error messages. If I click add button now (cloning) it is carrying error label tag to new cloned section. Because of this, if I removed data from a required field in first section, error message is displaying in both original section and cloned section.

我认为如果我可以在克隆时从原始部分删除错误标签,那应该可以解决问题.

I think if I can remove label for error from original section while cloning that should solve problem.

       $('#' + divID).find('input,select').each(function () {    
        $(this).attr('id', ($(this).attr('id')).slice(0,-1) + uniqueId);    
        $(this).attr('name', ($(this).attr('name')).slice(0,-1) + uniqueId);
       $(this).val('');     

    });

我想在克隆时在上述条件下删除下面的行.

I would like to remove the below line within above condition while cloning.

   <label class="error" style="display: inline-block;" for="NameOnCard1">

推荐答案

您需要做的就是在新克隆的容器中搜索label.error元素:

All you need to do is search for label.error elements in the newly cloned container:

   container.find('label.error').remove();

这篇关于jQuery的克隆验证删除错误类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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