<!--选择文件上传--><script id="upload_file_dialog" type="text/html"> ???<div class="layui-form-item"> ???????<label class="layui-form-label">文件上传</label> ???????<div class="layui-input-block"> ???????????<button type="button" class="layui-btn" onclick="$(‘input[name=uploadfile]‘).click();"> ???????????????<i class="layui-icon"></i>上传文件 ???????????</button> ???????????<input type="file" name="uploadfile" style="display: none;" /> ???????</div> ???????<label class="layui-form-label" style="width: 100%; text-align: left; padding-left: 110px;color:red;" ???????????id="uploadFileName"> ???????????文件上传</label> ???</div></script>
//文件上传change事件$("input[name=uploadfile][type=file]").on("change", function (e) { ???var filePath = $(this).val(); ???filePath = filePath.substring(filePath.lastIndexOf("\\")+1); ???$("#uploadFileName").text(filePath);});
function selectFileClick() { ???//判断浏览器版本 ???if (webim.BROWSER_INFO.type == ‘ie‘ && parseInt(webim.BROWSER_INFO.ver) <= 9) { ???????layui.layer.msg(‘上传文件暂不支持ie9(含)以下浏览器‘); ???????//$(‘#updli_file_form‘)[0].reset(); ???????//$(‘#upload_file_low_ie_dialog‘).modal(‘show‘); ???} else { ???????layui.layer.open({ ???????????title: "文件上传", ???????????content: $(‘#upload_file_dialog‘).html(), ???????????area: [‘500px‘, ‘300px‘], ???????????btn: [‘发送‘, ‘取消‘], ???????????yes: function (index, layero) {//发送 ???????????????uploadFileBoxIndex = index; ???????????????uploadFile(); ????????????}, ???????????btn2:function(index, layero) {//取消 ???????????????????????????} ???????}); ???????//文件上传change事件 ???????$("input[name=uploadfile][type=file]").on("change", function (e) { ???????????var filePath = $(this).val(); ???????????filePath = filePath.substring(filePath.lastIndexOf("\\")+1); ???????????$("#uploadFileName").text(filePath); ???????}); ???}}
layui-open-上传文件
原文地址:https://www.cnblogs.com/zhyue93/p/layui-open.html