我的标记
这个JQuery代码
每次按下播放时都会一直给我错误
<div class = "container">
<legend><strong>Zedd - Spectrum</legend></h4>
<div class = "art-item"><img src="uploads/arts/default.jpg"></div>
<audio class = "audio-player" src = "uploads/tracks/02 So Far.mp3">
</audio>
<div class = "playerContainer">
<ul id = "playerControls" >
<li class = "play-bt"></li>
<li class = "pause-bt"></li>
<li><div class ="progressContainer"><!-- Progess bars container //-->
<div class ="progressbar"></div>
</div>
</li>
</ul>
<span class ="timecode">0:00</span>
</div>
</div>
<div class = "container">
<legend><strong>Zedd - Spectrum</legend></h4>
<div class = "art-item"><img src="uploads/arts/default.jpg"></div>
<audio class = "audio-player" src = "uploads/tracks/track3.mp3">
</audio>
<div class = "playerContainer">
<ul id = "playerControls" >
<li class = "play-bt"></li>
<li class = "pause-bt"></li>
<li><div class ="progressContainer"><!-- Progess bars container //-->
<div class ="progressbar"></div>
</div>
</li>
</ul>
<span class ="timecode">0:00</span>
</div>
</div>
每次点击播放时,它都会一直给我这个错误
Uncaught TypeError: Object #<Object> has no method 'play'
是不是音频标签有播放方法?
答案 0 :(得分:6)
jQuery的.find()
返回jQuery object,而非原生HTMLAudioElement
,因此您需要.find()
返回unwrap the value:
$artItem.find('audio')[0].play();
// or
$artItem.find('audio').get(0).play();
答案 1 :(得分:1)
您可以访问jquery,而不是此处的普通dom标记 所以试试:
$artItem.find("audio")[0].play()