您好,登錄后才能下訂單哦!
在使用layui的多圖上傳時(shí)發(fā)現(xiàn)沒(méi)有刪除功能
在網(wǎng)上搜索解決辦法時(shí)有的感覺(jué)太復(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" > 預(yù)覽圖: <div class="layui-upload-list uploader-list" 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 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)離開(kāi) $(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è)參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。