js实现带进度条提示的多视频上传功能

js实现带进度条提示的多视频上传功能

引用:

<link href="https://www.jb51.net/bootstrap.css" > <script src="https://www.jb51.net/jquery.fileupload.js"></script> <script src="https://malsup.github.com/jquery.form.js"></script>

html:

<div> <label>产品视频:</label> <div> <input type="file"><a href="javascript:;" >删除</a> <div> <div> <div role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100"> <span>0% Complete</span> </div> </div> <div></div> <div></div> <input type="hidden" value=""> <p></p> </div> </div> <div> <input type="file"><a href="javascript:;" >删除</a> <div> <div> <div role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100"> <span>0% Complete</span> </div> </div> <div></div> <div></div> <input type="hidden" value=""> <p></p> </div> </div> </div>

script:

//上传视频 $(".avatarVideo").change(function() { var _this = $(this); _this.wrap("<form action='/admin/uploadimg/addVideo' method='post' enctype='multipart/form-data'></form>"); _this.parents('.fileUploadeVideo').ajaxSubmit({ dataType: 'json', beforeSend: function () { $(".progress").show(); }, uploadProgress: function (event, position, total, percentComplete) { var percentVal = percentComplete + '%'; _this.parents('.videoUpfile').find(".progress-bar").width(percentComplete + '%'); _this.parents('.videoUpfile').find(".progress-bar").html(percentVal); _this.parents('.videoUpfile').find(".sr-only").html(percentComplete + '%'); }, success: function (data) { if(data.code==100) { _this.parents('.videoUpfile').find(".files").html("文件名: " + data.video_title); _this.parents('.videoUpfile').find("input[type=hidden]").val(data.video_id); alert("上传成功!"); }else{ alert("上传失败"); } }, error: function () { alert("上传失败"); } });

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyjdsd.html