3

我正在自定义无法将源代码修改为的现有 ASP.NET 3.5 AJAX Web 应用程序(它是 SharePoint 2010)。

我需要添加一个单击事件处理程序作为关闭按钮上的第一个事件。但是,我想先检查一下已经在此按钮上注册的现有事件处理程序会做什么,所以我不会搞砸任何事情。

我仍在学习 ASP.NET AJAX,可以看到Sys.UI.DomEvent 类具有添加和删除事件处理程序的方法,但不能枚举它们。我了解 jQuery,并且熟悉 Chrome 中的 JavaScript 调试。

如何查看注册了哪些事件并在特定位置插入自定义事件处理程序?

4

1 回答 1

0

There is a technique that will at least allow you to be the first in line (unless another script employs the same trick - unlikely).

What you have to do is hijack the click event. This related question demonstrates the technique: Hijacking onchange event without interfering with original function

All we do is redefine the click function to be one of our own choosing, e.g.

var myButton = document.getElementById('button1')
var oldClick = myButton.click;

myButton.click = function(evt) {
  //do whatever you want.  When done, call the default click function:
  if (oldClick) oldClick(evt);
}

(the syntax in the linked question is superior, but the above code is easier to read).

于 2012-08-22T18:00:33.067 回答