Uncaught TypeError: Cannot read property 'call' of undefined on jQuery Validation

Uncaught TypeError: Cannot read property 'call' of undefined on jQuery Validation

我正在尝试验证表单输入以仅允许指定的文件类型

  $("#resumeFile").rules("add", {
            required: true,
            extension: "doc|pdf|docx",
            messages: {
                required: "Please select File",
                extension: "Accepted formats pdf, doc or docx"
            }
        });

当我删除 extension: "doc|csv|pdf|docx", 时它工作得很好,用 extension 检查它给出的错误 Uncaught TypeError: Cannot read property 'call' of undefined

这是你最好的线索并完美地解释了它:

When I remove extension: "doc|csv|pdf|docx", it works perfectly fine, with extension check its giving error Uncaught TypeError: Cannot read property 'call' of undefined

extension 方法未定义,因为它不是默认规则集的一部分。您必须包括 the additional-methods.js file,因为这是 extension 规则所在的位置。