仅播放top audio_tag按钮
我开始在我的网站上播放音频; 我以前在我的一个视图中实现了一个带有字形按钮的audio_tag。 在另一个视图中,我正在尝试列出我的所有单词对象,并且我希望有一个按钮来播放每个相关的音频。 截至目前,此function仅适用于此视图中列出的第一个单词对象。 如何在按钮中为视图中的所有对象播放声音?
课程显示视图:
Vocabulary
- ()
application.js中:
// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. // // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // //= require jquery //= require bootstrap-sprockets //= require jquery_ujs //= require_tree . jQuery(document).ready(function() { $("#audioButton").on("click", function() { $(".audio-play")[0].currentTime = 0; return $(".audio-play")[0].play(); }); });
给每个人一个自己独特的身份。
在HTML中,ID必须是唯一的。 例如“#audioButton1”“#audioButton2”等…或者,不要使用id,使用类名,例如class="btn btn-default audio-button"
然后$(".audio-button").on("click", function()
- Restangular:错误:未知提供者:RestangularProvider < – Restangular
- jQuery Remotipart将发送到服务器
- Rails 4 jQuery,javascript和咖啡脚本无法正常工作
- Rails 4 app …在开发环境中javascript不会触发,除非刷新页面
- Twitter Bootstrap .popover()函数在Rails中不起作用
- 使用CarrierWave和Rails设置Froala WYSIWYG编辑器
- 就像Ruby on Rails中的按钮Ajax一样
- 使用引导程序和使用选项卡时,迷你图未绘制
- 如何将Ruby数组传递给Javascript以生成折线图