layui上传组件使用方法分享
本文主要和大家分享layui上传组件使用方法,先贴上前端的代码,希望能帮助到大家。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>产品特性Form</title> <link href="~/Content/Base/layui/css/layui.css" rel="stylesheet" type="text/css" /> <script src="~/Content/Base/layui/layui.js" type="text/javascript"></script> <script src="../../../../Content/Views/js/jquery-1.8.3.min.js" type="text/javascript"></script> <script src="../../../../Content/Views/js/framework-ui.js" type="text/javascript"></script> <style> @*table { height: 150px; } .layui-form-label { width: 100px; }*@ </style></head><body> <p style="width:100%;"> <p class="layui-upload"> <button type="button" class="layui-btn layui-btn-normal" id="testList">选择多文件</button> <p class="layui-upload-list"> <table class="layui-table" id="tableFile"> <thead> <tr><th>文件名</th> <th>大小</th> <th>状态</th> <th>操作</th> </tr></thead> <tbody id="demoList"></tbody> </table> </p> <button type="button" class="layui-btn" id="testListAction">开始上传</button> </p> </p> <script> function getModelName() { var url = location.search; //获取url中"?"符后的字串 var theRequest = new Object(); if (url.indexOf("?") != -1) { var str = url.substr(1); strs = str.split("&"); for (var i = 0; i < strs.length; i++) { theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]); } } return theRequest; }; var parentUrlObj = getModelName(); var FileType = decodeURI(escape(parentUrlObj['filetype'])); var ModelId = decodeURI(escape(parentUrlObj['modelId'])); var NodeId = decodeURI(escape(parentUrlObj['nodeid'])); var ProductId = decodeURI(escape(parentUrlObj['productid'])); layui.use(['form', 'upload'], function () { var form = layui.form, upload = layui.upload; var demoListView = $('#demoList') , uploadListIns = upload.render({ elem: '#testList' , url: '/ModelList/uploadNodeAttributeFile?filetype=' + FileType + '&modelid=' + ModelId + '&nodeid=' + NodeId + '&productid=' + ProductId , accept: 'file' , multiple: true , auto: false , bindAction: '#testListAction' , choose: function (obj) { var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列 //读取本地文件 obj.preview(function (index, file, result) { var tr = $(['<tr id="upload-' + index + '">' , '<td>' + file.name + '</td>' , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>' , '<td>等待上传</td>' , '<td>' , '<button class="layui-btn layui-btn-mini demo-reload layui-hide">重传</button>' , '<button class="layui-btn layui-btn-mini layui-btn-danger demo-delete">删除</button>' , '</td>' , '</tr>'].join('')); //单个重传 tr.find('.demo-reload').on('click', function () { obj.upload(index, file); }); //删除 tr.find('.demo-delete').on('click', function () { delete files[index]; //删除对应的文件 tr.remove(); uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值,以免删除后出现同名文件不可选 }); demoListView.append(tr); }); } , done: function (res, index, upload) { if (res.Status == "success") { var tr = demoListView.find('tr#upload-' + index), tds = tr.children(); tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>'); return null; } else { if (res.Message == "文件已存在") { var tr = demoListView.find('tr#upload-' + index), tds = tr.children(); tds.eq(2).html('<span style="color: #5FB878;">上传失败,文件已存在</span>'); return null; } else { this.error(index, upload); } } } , error: function (index, upload) { var tr = demoListView.find('tr#upload-' + index) , tds = tr.children(); tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>'); tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传 } }); }); function heightTiao(nameid) { var oIframe = window.top.document.getElementById(nameid); var oBody = document.getElementsByTagName("body")[0]; oIframe.style.height = oBody.offsetHeight + 40 + 'px'; }; </script></body></html>
C#后端接收代码
HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;string str1 = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;string imgPath = "";string fileName = "";fileName = hfc[0].FileName;imgPath = Server.MapPath("~/bin/" + fileName);imgPath = Server.MapPath("~/bin/" + modelId + "/" + productid + "/" + nodeid + "/" + filetype + "/" + fileName);hfc[0].SaveAs(imgPath);return Content(new AjaxResult { Status = ResultType.success, Message = "执行成功" }.ToJson());
具体使用过程中需要注意的是
auto: false
bindAction: ‘#testListAction’
这两个参数主要是设定为当你选择文件时不上传文件,而指定某个按钮来执行上传的动作
假设需要选择文件时则执行上传动作,只需要把auto设为true,并且去掉bindAction这个参数
其它参数可参照layui官网文档
上传文件需要判断的很多,只是简单记录个例子方便自己以后的使用。
相关推荐:
以上是layui上传组件使用方法分享的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

1、首先我们进入到网易云音乐中,然后在软件首页界面中,点击进入到歌曲的播放界面中。2、然后在歌曲播放界面中,找到右上方的分享功能按钮,如下图红框所示位置,点击选择分享的渠道;在分享渠道中,点击底部的“分享至”选项,然后选择第一个“微信朋友圈”,即可将内容分享至微信朋友圈。

layui 提供了多种获取表单数据的方法,包括直接获取表单所有字段数据、获取单个表单元素值、使用 formAPI.getVal() 方法获取指定字段值、将表单数据序列化并作为 AJAX 请求参数,以及监听表单提交事件获取数据。

近期,百度网盘安卓客户端迎来了全新的8.0.0版本,这一版本不仅带来了众多变化,还增添了诸多实用功能。其中,最为引人注目的便是文件夹共享功能的增强。现在,用户可以轻松邀请好友加入,共同分享工作和生活中的重要文件,实现更加便捷的协作与共享。那么究竟该如何分享给好友自己需要分享的文件呢,下文中本站小编就将为大家带来详细内容介绍,希望能帮助到大家!1)打开百度云APP,首先点击在首页中选择相关的文件夹,然后再点击界面右上角的【...】图标;(如下图)2)随后点击“共享成员”一栏中的【+】,最后在勾选所

layui 登录页面跳转设置步骤:添加跳转代码:在登录表单提交按钮点击事件中添加判断,成功登录后通过 window.location.href 跳转到指定页面。修改 form 配置:在 lay-filter="login" 的 form 元素中添加 hidden 输入字段,name 为 "redirect",value 为目标页面地址。

通过使用layui框架的响应式布局功能,可以实现自适应布局。步骤包括:引用layui框架。定义自适应布局容器,设置layui-container类。使用响应式断点(xs/sm/md/lg)隐藏特定断点下的元素。利用网格系统(layui-col-)指定元素宽度。通过偏移量(layui-offset-)创建间距。使用响应式实用工具(layui-invisible/show/block/inline)控制元素的可见性和显示方式。

layui与Vue的区别主要体现在功能和关注点上。layui专注于快速开发UI元素,提供预制组件简化页面构建;而Vue是一个全栈框架,注重数据绑定、组件化开发和状态管理,更适合构建复杂应用程序。 layui学习简单,适合快速构建页面;Vue学习曲线陡峭,但有助于构建可扩展和易维护的应用程序。根据项目需求和开发者技能水平,可以选择合适的框架。

要运行 layui,请执行以下步骤:1. 导入 layui 脚本;2. 初始化 layui;3. 使用 layui 组件;4. 导入 layui 样式(可选);5. 确保脚本兼容并注意其他注意事项。通过这些步骤,您就可以使用 layui 的强大功能构建 web 应用程序。

layui框架是一款基于JavaScript的前端框架,提供了一套易用的UI组件和工具,帮助开发者快速构建响应式Web应用。其特点包括:模块化、轻量级、响应式,并拥有完善的文档和社区支持。layui广泛应用于管理后台系统、电商网站和移动端应用等开发中。优点在于上手快、提高效率、维护方便,缺点是定制性较差、技术更新较慢。
