HTML5音频和jQuery [英] HTML5 Audio and jQuery

查看:159
本文介绍了HTML5音频和jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用一个按钮来启动使用jQuery在HTML5音频标签的轨道,但我不断收到一个错误。

I am trying to use a button to start a track in an HTML5 audio tag using jQuery, but I keep getting an error.

var song = $('#audio');

$('#play').click(function() {
song.play();
});

当我使用的document.getElementById('声音'),它的工作原理,但使用jQuery选择我收到以下错误时:

When I use document.getElementById('audio'), it works, but when using the jQuery selector I get the following error:

未捕获类型错误:对象的翻译:没有方法播放

Uncaught TypeError: Object [object Object] has no method 'play'

感谢您的帮助。

推荐答案

尝试获得本机的DOM元素的jQuery知道返回的包裹阵列上任何关于 .play 方法在 $('#音频')选择:

Try getting the native DOM element as jQuery knows nothing about .play method on the wrapped array returned by the $('#audio') selector:

song.get(0).play();

这篇关于HTML5音频和jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆