下面是帶jQuery的jPlayer的代碼。我必須創建jPlayer動態。如何創建動態jPlayer?
$("#jquery_jplayer_0").jPlayer({
ready: function() {
$(this).jPlayer("setMedia", {
webmv: "http://....",
poster: "http://...."
});
},
play: function() { // To avoid both jPlayers playing together.
$(this).jPlayer("pauseOthers");
},
repeat: function(event) { // Override the default jPlayer repeat event handler
if(event.jPlayer.options.loop) {
$(this).unbind(".jPlayerRepeat").unbind(".jPlayerNext");
$(this).bind($.jPlayer.event.ended + ".jPlayer.jPlayerRepeat", function() {
$(this).jPlayer("play");
});
} else {
$(this).unbind(".jPlayerRepeat").unbind(".jPlayerNext");
$(this).bind($.jPlayer.event.ended + ".jPlayer.jPlayerNext", function() {
$("#jquery_jplayer_1").jPlayer("play", 0);
});
}
},
swfPath: "js",
supplied: "webmv",
size: {
width: "640px",
height: "360px",
cssClass: "jp-video-360p"
},
cssSelectorAncestor: "#jp_container_0"
});
我在頁面加載時有20個jPlayers。所以我不想寫這20次。
for(var i=1;i<=20;i++){
$("#jquery_jplayer_"+i).jPlayer({
ready: function() {
$(this).jPlayer("setMedia", {
webmv: "http://..",
poster: "http://.."
});
},
play: function() { // To avoid both jPlayers playing together.
$(this).jPlayer("pauseOthers");
},
repeat: function(event) { // Override the default jPlayer repeat event handler
if(event.jPlayer.options.loop) {
$(this).unbind(".jPlayerRepeat").unbind(".jPlayerNext");
$(this).bind($.jPlayer.event.ended + ".jPlayer.jPlayerRepeat", function() {
$(this).jPlayer("play");
});
} else {
$(this).unbind(".jPlayerRepeat").unbind(".jPlayerNext");
$(this).bind($.jPlayer.event.ended + ".jPlayer.jPlayerNext", function() {
$("#jquery_jplayer_"+(i-1)).jPlayer("play", 0);
});
}
},
swfPath: "jplayer/js",
supplied: "webmv",
size: {
width: "640px",
height: "360px",
cssClass: "jp-video-360p"
},
cssSelectorAncestor: "#jp_container_"+i
});
}
我想申請上面的代碼。但它不適合我。可能它不會創建動態對象。使用eval()但不起作用。