}
---------------------------------------------------------------------------
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>{$title}</title> <script type="text/javascript" src="http://imcp.ifeng.com/resource/js/jquery/jquery-1.3.2.min.js"></script> </head> <body> <if condition="$info.msg"> <img src="{$info.msg}"> </if> <img src="__PUBLIC__/php2E16.jpg" alt="" /> <form id="form1" action="{:U('Privilege/douploadimg')}" method="post" enctype="multipart/form-data"> <input type="hidden" name="map_pic_id" id="map_pic_id" value=""> <table width="100%" id="gallery-table" align="center"> <!-- 图片列表 --> <tr> <td> <if condition="$infoall"> <foreach name="infoall" item="vo"> <div id="gallery_1" style="float:left; text-align:center; border: 1px solid #DADADA; margin: 4px; padding:2px;"> <a href="javascript:;" onclick="if (confirm('您确定要删除该图片么?')) dropImg('1')">[-]</a><br /> <a href="{$vo.msg}" target="_blank"><img src="{$vo.msg}" border="0" width="160"></a> </div> </foreach> </if> </td> </tr> <tr> <td> </td> </tr> <tr> <td> <a href="javascript:;" onclick="addImg(this)">[+]</a> 上传文件 <input type="file" name="dtfiledata[]" /> </td> </tr> </table> <input type="file" name="filedata" /> <input type="submit" value="提交"> </form> <script language="JavaScript"> <!-- var Browser = new Object(); Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined'); Browser.isIE = window.ActiveXObject ? true : false; Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != - 1); Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != - 1); Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != - 1); function rowindex(tr) { if (Browser.isIE) { return tr.rowIndex; } else { table = tr.parentNode.parentNode; for (i = 0; i < table.rows.length; i ++ ) { if (table.rows[i] == tr) { return i; } } } } /** * 新增一个图片 */ function addImg(obj) { var src = obj.parentNode.parentNode; var idx = rowindex(src); var tbl = document.getElementById('gallery-table'); var row = tbl.insertRow(idx + 1); var cell = row.insertCell(-1); cell.innerHTML = src.cells[0].innerHTML.replace(/(.*)(addImg)(.*)(\[)(\+)/i, "$1removeImg$3$4-"); } /** * 删除图片上传 */ function removeImg(obj) { var row = rowindex(obj.parentNode.parentNode); var tbl = document.getElementById('gallery-table'); tbl.deleteRow(row); } /** * 删除图片 */ function dropImg(imgId) { var map_pic_id = $('#map_pic_id').val(); $('#map_pic_id').val(map_pic_id.replace(imgId + ',', '')); dropImgResponse(imgId); } function dropImgResponse(result) { document.getElementById('gallery_' + result).style.display = 'none'; } //--> </script> </body> </html>
以上只展示前端部分,js对图片的增减