'覆盖'javascript函数

jua*_*uan 2 javascript asp.net menu

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

我注意到这些项目被渲染为使用名为Menu_Key的javascript函数

<td id="ctl00_MainMenun1" onmouseover="Menu_HoverStatic(this)" onmouseout="Menu_Unhover(this)" onkeyup="Menu_Key(this)">
Run Code Online (Sandbox Code Playgroud)

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

Mar*_*ger 6

在最初定义函数后重新定义函数,但在var中跟踪它以便稍后调用它.您将有效地重命名原始的Menu_Key函数.

var originalMenu_Key = Menu_Key;

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

   if ( /* everything validated */ ) {
     originalMenu_Key (t);
   }
};
Run Code Online (Sandbox Code Playgroud)