如何在不修改jquery.validate.unobtrusive.min.js的情况下重写JQuery非干扰方法? [英] How to override a JQuery unobtrusive method without modifying jquery.validate.unobtrusive.min.js?

查看:70
本文介绍了如何在不修改jquery.validate.unobtrusive.min.js的情况下重写JQuery非干扰方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写jquery.validate.unobtrusive.js中的onErrors方法,以将错误消息显示为指向html元素的超链接.但是,我不想更改jquery.validate.unobtrusive.js中的方法,因为此文件会随着更新版本的发布而更新.我已经读到可以创建一个外部JS文件并在其中包含onErrors函数.在我的html文件中,如果在添加jquery.validate.unobtrusive.js之后添加了外部JS文件,则它应自动覆盖jquery.validate.unobtrusive.js中的方法.这没有发生.

I want to override the onErrors method in jquery.validate.unobtrusive.js to display error messages as hyper links to the html elements. However, I don't want to change the method in jquery.validate.unobtrusive.js since this file gets updated as newer versions become available. I have read that I can create an external JS file and include the onErrors function there. In my html file, if I include the external JS file AFTER I include jquery.validate.unobtrusive.js then it should automatically override the method in jquery.validate.unobtrusive.js. This is not happening.

请注意,我使用jquery.validate.unobtrusive.min.js,并且该函数从onErrors重命名为k.我尝试在外部JS文件中创建一个名为"k"的函数,但是没有这种运气.

Please note that I use jquery.validate.unobtrusive.min.js and the function is renamed from onErrors to k. I tried creating a function called 'k' in my external JS file but no such luck.

谢谢!

推荐答案

当两个函数都放在全局命名空间中时,可能会覆盖.如果是jquery.validation.unobtrusive.js函数,则onErrors会在其他函数内部内部声明,并且无法通过声明相同名称的其他函数来替换.

Overriding may happen when both functions are placed in global namespace. In case of jquery.validation.unobtrusive.js function onErrors is declared internally inside other function and cannot be replaced by declaring other function with the same name.

似乎没有更改源代码就无法更改该功能的方法.

Seems there is no way to alter that function without changing source code.

这篇关于如何在不修改jquery.validate.unobtrusive.min.js的情况下重写JQuery非干扰方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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