1. How to convert pictures into icon code
html code:
<div class="yanzRight"> <input style="margin-top:5px;float: left;" name="evidence" onchange="previewImage(this,5)" type="file"/> <span class="dui" style="display: none;"></span> </div> <div style="margin-left:150px;clear:both; padding-top:15px;"> <img src="" alt="" height="200" width="200" style="display:none;"/> </div>
js code
//Picture preview functionfunction previewImage(file,imgNum) { var MAXWIDTH = 200; var MAXHEIGHT = 200; var div = ('preview'+imgNum); if ( && [0]) { ='<img id=imghead'+imgNum+'>'; var img = ('imghead'+imgNum+''); = function(){ var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, , ); = ; = ; // = +'px'; = +'px'; } var reader = new FileReader(); = function(evt){ = ;} ([0]); } else // { var sFilter='filter:progid:(sizingMethod=scale,src="'; (); var src = ().text; = '<img id=imghead'+imgNum+'>'; var img = ('imghead2'); ('').src = src; var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, , ); status =('rect:'++','++','++','+); = "<div id=divhead"+imgNum+" style='width:"++"px;height:"++"px;margin-top:"++"px;"+sFilter+src+"\"'></div>"; } } function clacImgZoomParam( maxWidth, maxHeight, width, height ){ var param = {top:0, left:0, width:width, height:height}; if( width>maxWidth || height>maxHeight ) { rateWidth = width / maxWidth; rateHeight = height / maxHeight; if( rateWidth > rateHeight ) { = maxWidth; = (height / rateWidth); }else { = (width / rateHeight); = maxHeight; } } = ((maxWidth - ) / 2); = ((maxHeight - ) / 2); return param; }
2. Another method of using js to select multiple images at a time to preview and display
<html xmlns="http:///1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test page</title> <script type="text/javascript"> //The following is used for the preview function of multiple pictures upload function setImagePreviews(avalue) { var docObj = ("doc"); var dd = ("dd"); = ""; var fileList = ; for (var i = 0; i < ; i++) { += "<div style='float:left' > <img id='img" + i + "' /> </div>"; var imgObjPreview = ("img"+i); if ( && [i]) { //Under Firefox, set the img attribute directly = 'block'; = '150px'; = '180px'; // = [0].getAsDataURL(); //The Firefox 7 or above cannot be obtained using the getAsDataURL() method above, and the following method is required = ([i]); } else { //Use filters under IE (); var imgSrc = ().text; alert(imgSrc) var localImagId = ("img" + i); //The initial size must be set = "150px"; = "180px"; //Catch the image exception to prevent users from modifying the suffix to forge pictures try { = "progid:(sizingMethod=scale)"; ("").src = imgSrc; } catch (e) { alert("The image you uploaded is incorrect, please re-select!"); return false; } = 'none'; (); } } return true; } </script> </head> <body> <div style="margin :0px auto; width:990px;"> <input type="file" name="file" multiple="multiple" style="width:150px;" onchange="javascript:setImagePreviews();" accept="image/*" /> <div style=" width:990px;"></div> </div> </body> </html>
The above two methods (recommended) for implementing the upload and preview of multiple pictures in the js front-end article are all the content I share with you. I hope you can give you a reference and I hope you can support me more.