layui多圖上傳實(shí)現(xiàn)刪除功能的例子
在使用layui的多圖上傳時(shí)發(fā)現(xiàn)沒有刪除功能
在網(wǎng)上搜索解決辦法時(shí)有的感覺太復(fù)雜有的不符合自己所需要的所以就自己動(dòng)手
下面附上代碼
HTML:
<div class="layui-upload"> <button type="button" class="layui-btn" id="test2">多圖片上傳</button> <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;width: 88%"> 預(yù)覽圖: <div class="layui-upload-list uploader-list" style="overflow: auto;" id="uploader-list"> </div> </blockquote> </div>
CSS:
<style type="text/css"> .uploader-list { margin-left: -15px; } .uploader-list .info { position: relative; margin-top: -25px; background-color: black; color: white; filter: alpha(Opacity=80); -moz-opacity: 0.5; opacity: 0.5; width: 100px; height: 25px; text-align: center; display: none; } .uploader-list .handle { position: relative; background-color: black; color: white; filter: alpha(Opacity=80); -moz-opacity: 0.5; opacity: 0.5; width: 100px; text-align: right; height: 18px; margin-bottom: -18px; display: none; } .uploader-list .handle span { margin-right: 5px; } .uploader-list .handle span:hover { cursor: pointer; } .uploader-list .file-iteme { margin: 12px 0 0 15px; padding: 1px; float: left; } </style>
js:
upload.render({ elem: '#test2' ,url: '' ,multiple: true ,before: function(obj){ layer.msg('圖片上傳中...', { icon: 16, shade: 0.01, time: 0 }) } ,done: function(res){ layer.close(layer.msg());//關(guān)閉上傳提示窗口 //上傳完畢 $('#uploader-list').append( '<div id="" class="file-iteme">' + '<div class="handle"><span class="glyphicon glyphicon-trash"></span></div>' + '<img style="width: 100px;height: 100px;" src=https://'+ res.href +'>' + '<div class="info">' + res.name + '</div>' + '</div>' ); } });
$(document).on("mouseenter mouseleave", ".file-iteme", function(event){ if(event.type === "mouseenter"){ //鼠標(biāo)懸浮 $(this).children(".info").fadeIn("fast"); $(this).children(".handle").fadeIn("fast"); }else if(event.type === "mouseleave") { //鼠標(biāo)離開 $(this).children(".info").hide(); $(this).children(".handle").hide(); } });
// 刪除圖片 $(document).on("click", ".file-iteme .handle", function(event){ $(this).parent().remove(); });
以上這篇layui多圖上傳實(shí)現(xiàn)刪除功能的例子就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
javascript實(shí)現(xiàn)按回車鍵切換焦點(diǎn)
這篇文章主要介紹了javascript實(shí)現(xiàn)按回車鍵切換焦點(diǎn)的方法,需要的朋友可以參考下2015-02-02JS實(shí)現(xiàn)給不同元素設(shè)置不同的定時(shí)器
這篇文章主要為大家詳細(xì)介紹了JS實(shí)現(xiàn)給不同元素設(shè)置不同的定時(shí)器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07easyui window refresh 刷新兩次的解決方法(推薦)
下面小編就為大家?guī)硪黄猠asyui window refresh 刷新兩次的解決方法(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-05-05js原生map實(shí)現(xiàn)的方法總結(jié)
在本篇文章里小編給大家整理了關(guān)于js原生map實(shí)現(xiàn)的方法以及實(shí)例分析內(nèi)容,需要的朋友們可以參考下。2020-01-01Javascript表格翻頁效果實(shí)現(xiàn)思路及代碼
表格翻頁的實(shí)現(xiàn)方式有很多,下面以js為例為大家詳細(xì)介紹下表格翻頁效果的具體實(shí)現(xiàn),感興趣的朋友可以參考下2013-08-08JS監(jiān)聽微信、支付寶等移動(dòng)app及瀏覽器的返回、后退、上一頁按鈕的事件方法
這篇文章主要介紹了JS監(jiān)聽微信、支付寶等移動(dòng)app及瀏覽器的返回、后退、上一頁按鈕的事件方法,需要的朋友可以參考下2016-08-08JavaScript數(shù)組排序功能簡(jiǎn)單實(shí)現(xiàn)
這篇文章主要介紹了JavaScript數(shù)組排序功能簡(jiǎn)單實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05