问题
i am trying to do a basic jplayer text link on click to play an mp3 file, but i am unable to get it to function as there is no sound. here is the code
$(document).ready(function(){
$("#jquery_jplayer").jPlayer({
ready: function (event) {
$('.voice').click(function(e) {
e.preventDefault();
$(this).jPlayer("setFile", $(this).attr('href')).jPlayer("play");
});
},
swfPath: "/ui/core/js/jPlayer/",
supplied: "mp3",
wmode: "window"
});
});
here is the html:
<table>
<tr>
<td>
<a href="music.mp3" class="voice">Listen</a>
</td>
</tr>
</table>
<div id="jquery_jplayer"></div>
what am i missing?
thanks
回答1:
there were a couple of things..
this
, when used within aclick
event refers to the clicked element, not your jPlayer element- there is no such jPlayer method as
setFile
- it'ssetMedia
try this:
$(document).ready(function(){
$("#jquery_jplayer").jPlayer({
swfPath: "/ui/core/js/jPlayer/",
supplied: "mp3",
wmode: "window"
});
$('.voice').click(function(e) {
e.preventDefault();
$("#jquery_jplayer")
.jPlayer("setMedia", {mp3: this.href })
.jPlayer("play");
});
});
来源:https://stackoverflow.com/questions/8524706/jplayer-text-link-does-not-play