Javascript 内联onclick函数(this)不调用jQuery方法
我在处理onclick事件时遇到了麻烦。 我的HTML: 问题是音频文件没有播放。 我还做了一些测试Javascript 内联onclick函数(this)不调用jQuery方法,javascript,jquery,html,event-handling,Javascript,Jquery,Html,Event Handling,我在处理onclick事件时遇到了麻烦。 我的HTML: 问题是音频文件没有播放。 我还做了一些测试 function sound(element){ alert(element.tagName); -> it worked alert(element.parent().tagName); -> not worked and so on with siblings() or next() 一定是出了什么事。请帮帮我。非常感谢。代替 function sound(elem
function sound(element){
alert(element.tagName); -> it worked
alert(element.parent().tagName); -> not worked and so on with siblings() or next()
一定是出了什么事。请帮帮我。非常感谢。代替
function sound(element){
$audio = element.siblings('.audio').first();
$audio.trigger('play');
}
试试这个
function sound(element){
$audio = $(element).siblings('.audio').first(); //here 'element' is just a DOM element you have to wrap 'element' in jquery wrapper.
$audio.trigger('play');
}
element
(您正在传递的this
)是本机DOM元素,而不是jQuery包装器!最好指出,onclick=”“
是一种过时的添加事件处理程序的方法。
function sound(element){
$audio = element.siblings('.audio').first();
$audio.trigger('play');
}
function sound(element){
$audio = $(element).siblings('.audio').first(); //here 'element' is just a DOM element you have to wrap 'element' in jquery wrapper.
$audio.trigger('play');
}