0

我尝试将新代码添加到已设置的事件中,并且不知道如何在不重新编写代码的情况下执行此操作?如您所见,我有一个onComplete事件,它在完成 Flash 文件后会引发 alert()。现在我还想打开一个 jQuery 对话框。我怎样才能做到这一点?

问候和感谢,
-lony

<html><head><title>testAddEvent</title>
    <script type="text/javascript" src="filesOthersForTesting/jquery-1.x.x.min.js"></script>
    <script type="text/javascript" src="filesFromJWPlayer/jwplayer.js"></script>
    <script type="text/javascript">
        $(function(){
            jwplayer('playerDiv-1').setup({
                flashplayer: 'filesFromJWPlayer/player.swf',
                file: 'sampleContent/bla.flv',
                provider: 'video',
                height: 300,
                width: 300,
                stretching: 'uniform',
                events: {
                    onComplete: function() {
                        alert('Complete!');
                    }
                }
            });
        });
    </script>
<body>
    <div id="playerDiv-1"></div>
</body>

更新 1:
此代码是一个示例。alert() 是一堆行的示例。一般的问题是,我可以向已经初始化的事件(events.onComplete)添加一些东西。类似于:events.onComplete = events.onComplete + 'new code here';对于参数。

@Pointy:是的,jQuery 1.3.2 已经过时,切换到 x ;)。

4

1 回答 1

0
function decorateBefore(target, decorator) {
    var fn = function () {
        decorator.apply(this, arguments);
        return target.apply(this, arguments);
    };
    // fix inheritance if it's constructor 
    // (it's not needed in your case)
    fn.prototype = target.prototype;
    return fn;
}    

someObj.onComplete = decorateBefore(someObj.onComplete, function(){
  // my code here
  // this function will accept same arguments as original, it's return value will be ignored
})
于 2012-06-13T15:14:29.663 回答