【问题标题】:Why I get this JavaScript error with jQuery Validate?为什么我在使用 jQuery Validate 时会出现这个 JavaScript 错误?
【发布时间】:2017-06-14 16:54:03
【问题描述】:

我在 asp.net mvc 5 项目中使用 jquery.unobtrusive 和 jquery.validate 库来验证客户端的用户注册。

在浏览器上出现此错误:

Uncaught TypeError: $(...).parents(...).andSelf is not a function
    at Object.parse (jquery.validate.unobtrusive.js:211)
    at HTMLDocument.<anonymous> (jquery.validate.unobtrusive.js:392)
    at mightThrow (jquery-3.1.1.js:3570)
    at process (jquery-3.1.1.js:3638)

我在我的项目中使用 jquery 3.1.1。这似乎是版本问题。

知道怎么解决吗?

【问题讨论】:

    标签: jquery asp.net-mvc jquery-validate unobtrusive-validation


    【解决方案1】:

    Uncaught TypeError: $(...).parents(...).andSelf 不是函数

    Read the jQuery docs.

    “我在我的项目中使用 jquery 3.1.1。”

    .andSelf() 方法已从 jQuery 版本 3 中删除

    它是the .addBack() method 的别名,应该改用它。

    【讨论】:

      【解决方案2】:

      就像@Sparky 所说,这是因为从 NuGet 获得的 Unobtrusive JS 文件(如果您在 Visual Studio 中使用 File->New 创建应用程序)使用了已弃用的 andSelf() 函数。

      要解决,请获取最新版本

      jquery.validate.unobtrusive.js jquery.validate.unobtrusive.min.js

      来自

      https://github.com/aspnet/jquery-validation-unobtrusive/tree/master/dist

      并替换项目中的那些。或从 nuget 下载/更新现有插件。

      更换后 确保清除浏览器缓存。 (如果您使用的是 chrome,请按 Control + F5)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-12-30
        • 1970-01-01
        • 2021-11-28
        • 2022-01-20
        • 2023-04-04
        • 2020-02-03
        • 1970-01-01
        相关资源
        最近更新 更多