jplayer和jquery,添加一个函数

Mic*_*sse 1 javascript jquery jplayer

jQuery("#jquery_jplayer_1").jPlayer({
    ready: function () {
        jQuery(this).jPlayer("setMedia", {
        mp3: "/wp-content/themes/casaluna/music/01_Yari.mp3",
        oga: "/wp-content/themes/casaluna/music/01_Yari.ogg"
        }).jPlayer("play");
        [...]
Run Code Online (Sandbox Code Playgroud)

嗨,在触发事件"播放"的地方,我想添加对函数的引用.(将检查是否在主页上)

我在哪里,以及如何分开这个片段,添加新功能?

Geo*_*ins 5

根据文档,您可以将处理程序附加到play事件,如下所示:

$("#jquery_jplayer_1").bind($.jPlayer.event.play, function(event) { // Add a listener to report the time play began
  // Get the pathname and homepage values in a manner suitable to your
  // application before the following check.
  if ( pathname != homepage ) {
      return false;
  }
});
Run Code Online (Sandbox Code Playgroud)

如果你需要取消绑定你的功能,你可以这样做:

$("#jquery_jplayer_1").unbind($.jPlayer.event.play); // Remove all play event listeners
Run Code Online (Sandbox Code Playgroud)

您可以在jQuery onload函数($(function() {...});)中的任何位置插入此代码以附加处理程序.