0

我在这里尝试使用 jquery 验证插件验证数组中的时间,并在错误时通过 bootstrap 的 popover() 函数。但它显示错误。

Cannot read property 'settings' of undefined 

这是我的代码。我想验证何时触发模糊事件...

 $("input").blur(function() {

             var check = $(this).closest('tr').find('input');
                $.validator.addMethod(check, function(value, element) {

                    return this.optional(element) || /^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/i.test(value);
                }, "please enter the valid time");
                $(this).validate({
                    rules: {
                        'checkin[]': {
                            required: true
                        },
                        'checkout[]': {
                            rules: {
                                required: true
                            }
                        }
                    },
                    showErrors: function(errorMap, errorList) {


                        $.each(errorList, function(index, value) {
                            value.popover({
                                html: true,
                                trigger: 'blur',
                                content: function() {
                                    return 'Empty Textbox';

                                }
                            });
                        });



                        $.each(this.successList, function(index, value) {
                            $(value).popover('hide');


                            var form_data = $(this).closest('tr').find('input').serialize();





                            $.ajax(
                                    {
                                        url: "<?php echo site_url("HomeController/calculate_time_lap"); ?>",
                                        type: 'POST',
                                        data: form_data,
                                        success: function(result)
                                        {
                                            alert(result);
                                            // $('input').closest('tr').find('.TextBox3').val(result);
                                        }
                                    });
                            return false;
                        });
                    }
                });


            });
4

1 回答 1

0

经过一段时间的努力,我终于找到了解决问题的方法......我们只需使用匹配功能以及jQuery验证插件的时间模式即可。

  $("input").blur(function() {
         if (!(this.value.match(/^(([0-1]?[0-9])|([2][0-3])):([0-5]?[0-9])(:([0-5]?[0-9]))?$/i))) {
                    $(this).popover({
                        html: true,
                        trigger: 'blur',
                        content: function() {
                            return 'Invalid Time';

                        }
                    });

                    return false;
                }
                else {



                    var form_data = $(this).closest('tr').find('input').serialize();
                }




                $.ajax(
                        {
                            url: "<?php echo site_url("HomeController/calculate_time_lap"); ?>",
                            type: 'POST',
                            data: form_data,
                            success: function(result)
                            {
                               // alert(result);
                                $('input').closest('tr').find('.TextBox3').val(result);
                            }
                        });

                return false;
            });
于 2013-06-20T05:36:45.007 回答