我试图在一些第三方代码使一个模态对话框出现之后,得到一段JavaScript运行。我看到劫持jQuery show功能的一个很整洁的想法,但不幸的是它不工作。我猜这个想法在2009年以前用于旧版本的jQuery,但现在不是最新版本。这是一个jsFiddle的实现和一个例子:
I'm trying to get a piece of our JavaScript run after some 3rd party code makes a modal dialog appear. I saw a pretty neat idea of hijacking the jQuery show function, but unfortunately it is not working. I'm guessing this idea used to work on an older version of jQuery back in 2009, but not now on the latest version. Here is a jsFiddle with the implementation and a sample:
jsfiddle/mkmurray/drv5w/2/
正如你可以看到,运行示例,它将提醒' beforeShow'事件,但不是'afterShow事件',并且有一些调试我可以看到它不是完全调用'newCallback'功能。
As you can see by running the sample, it will alert the 'beforeShow' event, but not the 'afterShow event' and with some debugging I can see that it is not calling the 'newCallback' function entirely.
提前谢谢任何您可以提供的帮助。
Thank you in advance with any help you can provide.
推荐答案看起来我能够通过解决方案。它涉及原始的几个因素:
Looks like I was able to work through a solution. It involved a few factors going wrong with the original:
这个jsFiddle可以在这里找到一个工作实现:
A working implementation can be found here at this jsFiddle:
http ://jsfiddle/mkmurray/drv5w/27/
这个实现非常依赖于jQuery而不改变 show 方法。所以你几乎不得不决定是否要修改你的第三方jQuery插件,而不是这样做。无论哪种方式,如果您想要获得最新的第三方插件或最新的jQuery,一些新的更改可能会破坏您的实现。所以这个解决方案不一定比修改你的第三方插件更好或更差。
This implementation is pretty dependent on jQuery not changing the method signature of the show method though. So you pretty much have to decide if you want to modify your 3rd party jQuery plugins instead of doing this. Either way, if you want to get latest of the 3rd party plugin or the latest jQuery, some new change could break your implementation. So this solution is not necessarily better or worse than modifying your third party plugins.
更多推荐
试图触发之前&在jQuery之后的事件show()
发布评论