采用jpalyer插件做的播放器
代码:
var player = $('#myJplayer');
$(document).ready(function(){
getPlaylist();
$('#preBtn').click(function(){
player.jPlayer('play');
});
});
function getPlaylist(){
player.jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {mp3:"http://image.xinlistatic.com/static/fm/20120319/201203191457274258.mp3"});
},
swfPath: "/js",
supplied: "m4a, oga,mp3"
});
};
程序并没有像预想的那样正常的播放歌曲。
修改后的代码:
var player;
$(document).ready(function(){
getPlaylist();
$('#preBtn').click(function(){
player.jPlayer('play');
});
});
function getPlaylist(){
player = $("#myJplayer");
player.jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {mp3:"http://image.xinlistatic.com/static/fm/20120319/201203191457274258.mp3"});
},
swfPath: "/js",
supplied: "m4a, oga,mp3"
});
};
修改后,播放正常。
这是为什么呢??
------解决方案--------------------
var player = $('#myJplayer');
执行这句的时候 DOM还没加载完,找不到myJplayer