<div class="codetitle"> <span><a style="CURSOR: pointer" data="77109" class="copybut" id="copybut77109" onclick="doCopy('code77109')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code77109"> <br> <br><br> <br> <br> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><title></title> <br> <br> <br><br><div id="divVideo"></div> <br><br>//因js水平有限,不喜勿噴,全當沒事看看,video是html5中的新控件,大家可以看看<br><br><script type="text/javascript"> <BR><BR>//mp4是ios、android普遍支援的格式<BR>function playVideo(opt) { <BR>if (typeof (opt) == "undefined") { <BR>alert("請傳入必要參數!"); <BR>return; <BR>} <BR>if (typeof (opt.elemt) == "undefined") { <BR>alert("請指定播放器要插入的物件!"); <BR>return; <BR>} <BR>if (typeof (opt.src) == "undefined") { <BR>alert("請指定要播放影片的路徑!"); <BR>return; <BR>} <BR>var _this = this; <BR>_this.elemt = opt.elemt; //播放器要插入的物件<BR>_this.src = opt.src; //影片的URL(必設) <BR>_this.width = opt.width > 0 ? opt.width "px" : "100%"; //寬度(預設100%) <BR>_this.height = opt.height > 0 ? opt.height "px" : "100%" ; //高度(預設100%) <BR>_this.autoplay = opt.autoplay == "true" ? "autoplay" : ""; //自動播放(true為自動播放) <BR>_this.poster = opt .poster; //影片封面,播放時的封面圖片<BR>_this.preload = opt.preload == "true" ? "preload" : ""; //預先載入(true時啟動載入) <BR>_this .loop = opt.loop == "true" ? "loop" : ""; //循環播放(true時循環播放) <BR>var str = "<video id='playVideo' controls "; //根據設置的屬性的值,拼字video控制項<BR>str = " width='" _this.width "' height='" _this.height "' " _this.autoplay " " _this.preload " " _this.loop " "; <BR>if (typeof (_this.poster) != "undefined") { <BR>str = " poster='" _this.poster "' >"; <BR>} else { <BR>str = " > "; <BR>} <BR>str = " <source src='" _this.src "' />"; <BR>str = ""; <BR>this.elemt.innerHTML = str; //將str放到要插入的物件<BR>} <BR>playVideo({ <BR>//所有參數,elemt和src為必填其他看需求怎麼要求<BR>//elemt為播放控制項要插入的容器,src為視訊檔案位址,preload為預先加載,autoplay是否頁面進入就自動播放<BR>//poster為播放前的遮照圖片,loop為是否循環播放,width和heigth預設100% <BR>elemt : document.getElementById("divVideo"), <BR>src: "3.mp4", <BR>preload: "true", <BR>autoplay: "true", <BR>poster: "", <BR> loop: "true", <BR>width: "", <BR>heigth:"" <BR>}); <BR></script> </div>