jquery验证器插件,如何在即时创建的表单上应用它?

时间:2021-05-08 20:33:09

I am having following js code(similar-sample here) that creates form

我正在跟随创建表单的js代码(此处为类似示例)

function addsection(){
   var newForm = $("<form id='forma1'/>").submit(submit call here).validate();

   --for loop i 1 to 5
   {
       var inpt = $("<input />").attr('name', 'inpt').addclass('required').appento(newform);
       if(x)
          inpt.att('type', 'checkbox');
       else
          inpt.att('type', 'radio');
   }

   $('#div1').append(newForm);
}

Problem is it does not do validation.

问题是它没有做验证。

To perform validation i have done

为了执行我已经完成的验证

1> called validation() function (also tried calling at bottom of code once everything is added into form but same result)

1>调用validation()函数(一旦将所有内容添加到表单中但同样的结果,也尝试在代码底部调用)

2> added required class for input

2>添加了输入所需的类

How can i apply validation using jquery validator plugin in here? is there anything i am doing wrong in here

如何使用jquery验证器插件在此处应用验证?我在这里做错了什么吗

1 个解决方案

#1


The problem is probably that you first call validate and then you are adding validation information.

问题可能是您首先调用validate然后添加验证信息。

Try appending the form first and then calling validate.

尝试先添加表单然后调用validate。

#1


The problem is probably that you first call validate and then you are adding validation information.

问题可能是您首先调用validate然后添加验证信息。

Try appending the form first and then calling validate.

尝试先添加表单然后调用validate。