简体   繁体   English

在 JS 回调上调用 jquery 插件函数

[英]Calling jquery plugin functions on JS callback

I've searched for an answer to this question but haven't had any success.我一直在寻找这个问题的答案,但没有任何成功。 I am using the audio.js plugin for audio playback and usually stream files with:我正在使用audio.js插件进行音频播放,通常使用 stream 文件:

// within index.html.erb
audio.load($('.track_info a', clicked_node).attr('data-src'));
audio.play();

When placed in a script block on any html page, it works perfectly.当放置在任何 html 页面上的脚本块中时,它可以完美运行。 The problem I'm having involved attempting to call the audio plugin through a js callback.我涉及尝试通过 js 回调调用音频插件的问题。 Nothing happens when I do the following:当我执行以下操作时没有任何反应:

// callback.js.erb
audio.load('<%= "#{@song.sample_url}" %>');
audio.play();

Even when I wrap that with:即使我用以下方式包装它:

$.getScript('/javascripts/audio.js', function(){
    alert("Successfully loaded audio.");
)};

Any ideas?有任何想法吗?

ps - The other jquery within callback.js.erb work properly. ps - callback.js.erb 中的其他 jquery 工作正常。

Try this:尝试这个:

$.getScript('/javascripts/audio.js', function(){
    audio.load('<%= @song.sample_url %>');
    audio.play();
)};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM