我在处理onclick事件时遇到了麻烦。 我的HTML:内联onclick函数(这个)不调用jQuery方法
<div>
<button onclick="sound(this)">Listen</button>
<audio class="audio" src="example.mp3"></audio>
</div>
我的JS(jQuery的):
function sound(element){
$audio = element.siblings('.audio').first();
$audio.trigger('play');
}
的事情是不是播放的音频文件。 我也做了一些测试。
function sound(element){
alert(element.tagName); -> it worked
alert(element.parent().tagName); -> not worked and so on with siblings() or next()
东西一定是错的。请帮助我。非常感谢。
'element'(了'this'您传递)是土生土长的DOM元素,而不是一个jQuery的包装! – Bergi 2014-09-22 11:34:39