admin管理员组文章数量:1327748
I need to add some validations before the user navigates away via an ASP.NET Menu.
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?
I need to add some validations before the user navigates away via an ASP.NET Menu.
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?
Share Improve this question asked Jun 1, 2009 at 14:17 juanjuan 82k52 gold badges164 silver badges198 bronze badges5 Answers
Reset to default 6Redefine 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);
}
};
Above solution is a valid one, but in mon case redefinition can be done in a bit more flexible way
var originalMenu_Key = Menu_Key;
Menu_Key = function(t) {
// do your validations here
if ( /* everything validated */ ) {
return originalMenu_Key.apply(this,argumets);
}
};
In such case , any changes in function signature , will not break wrapping logic.
Just redefine the function at the bottom of the page (technically after the initial declaration).
You have more than one way to do this. Depend of what you want.
If you want a function to run before the existing one then add this.
<td id="ctl00_MainMenun1" onmouseover="Menu_HoverStatic(this)"
onmouseout="Menu_Unhover(this)" onkeyup="my_Function(); Menu_Key(this);">
If you want to run the second function conditionally then add this
<td id="ctl00_MainMenun1" onmouseover="Menu_HoverStatic(this)"
onmouseout="Menu_Unhover(this)" onkeyup="my_Function(this);">
function my_Function(sender)
{
if(valid)
Menu_Key(sender);
}
Use the js code:
$(document).ready(function () {
$("td").mouseover(function(){
alert('MouseOver validation content goes here.');
}).mouseout(function(){
alert('MouseOut validation content goes here.');
});
hth!
本文标签: aspnet39overriding39 javascript functionStack Overflow
版权声明:本文标题:asp.net - 'overriding' javascript function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742230843a2437192.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论