'覆盖'javascript函数 [英] 'overriding' javascript function

查看:155
本文介绍了'覆盖'javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用户通过ASP.NET菜单导航离开之前添加一些验证。

I need to add some validations before the user navigates away via an ASP.NET Menu.

我注意到,项目呈现使用名为Menu_Key JavaScript函数

I noticed that the items are rendered to use a javascript function called Menu_Key

<td id="ctl00_MainMenun1" onmouseover="Menu_HoverStatic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(this)">

我有没有办法覆盖功能,并具有菜单执行我的一个,从中我可以验证我需要什么,然后调用原始的?

I there a way to override that function and have the menu execute one of mine, from which I could validate what I need and then call the original?

推荐答案

重新定义功能,它最初定义后,但跟踪它的变种,这样以后可以调用它。你会有效地重命名原来Menu_Key功能。

Redefine the function after it was initially defined, but keep track of it in a var so that you can call it later. You would effectively be renaming the original Menu_Key function.

var originalMenu_Key = Menu_Key;

Menu_Key = function(t) { 
   // do your validations here

   if ( /* everything validated */ ) {
     originalMenu_Key (t);
   }
};

这篇关于'覆盖'javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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