<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><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> <br> <br> <br> </div>