效果如下:
HTML:
<div> <div id = "Showtherimage"> </div> <span id = "openidcardimg"> <span> </span> <入力タイプ= "id =" other_inputfile "name =" youndimg "/> </span> </div> </div>
.basicinfo .item {padding:.5rem .5rem 0; border-top:.3rem solid #eeeee;}。basicinfo li {overflow:hidden;マージンボトム:.5rem; line-height:2.1rem; Border-Bottom:1PX Solid#E3E3E3;}。BasicInfo Li:Last-Child {Border-Bottom:None;}。BasicInfo input [type = "text"] {height:2rem; line-height:2rem;}。basicinfo textarea {height:8rem; line-height:1.5rem;}。basicinfo .otherpic {min-height:3rem;}。basicinfo .otherpic .addpic {height:3rem;ラインハイト:3REM;フォントサイズ:3REM;マージンボトム:.5rem;}。basicInfo .otherpic img {margin:0 .5rem .5rem 0;幅:3REM;高さ:3REM;垂直アライイン:トップ;境界線:1px solid #ddd;}。basicinfo .yy_inputfile {position:absolute;上:0;左:0;幅:3REM;高さ:3REM;不透明:0;}。basicInfo .aboutpic {margin-bottom:.5rem; Line-Height:1.5rem; }JS:
var img_arr = new Array(); //相关图片$(page).on( 'change'、 '#other_inputfile'、function(){$(this)..resizeimage({this:this、cutwid: ''、quality:0.6、limitwid:710、function:function(data){var len = $( '#showotherimage')。 img = '<div style = "float:">' + '<img src = "' + img_arr '">' + '<span sid = "other_img _' + 9){#openIdcardimg ')。 //删除相关图片$(page).on( 'click'、 '。deletedimages'、function(){var sid = $(this).attr( 'sid'); img_arr.splice(sid、1); $(this).parent()。 {var img = '<div style = "float:">' + '<img src = "' + img_arr [i]"> ' +' <sid = "other_img_ ' +'" 9){$( '#openidcardimg')。show(); (data){ *何かをします... *} *}) * * */ $ .fn.resizeimage = function(obj){var file = obj.that.files [0]; var url = window.url || window.webkiturl; var blob = url.createobjecturl(file); var base64; var img = new Image(); img.src = blob; if(!/image /// w+/。test(obj.that.files [0] .type)){$ .toast( "请上传图片!"、1000); falseを返します。 } img.onload = function(){if(img.width <obj.limitwid){$ .toast( '图片宽度不得小于' + obj.limitwid + 'px'、1000); falseを返します。 } var that = this; //生成比例var w、スケール、h = that.height; if(obj.cutwid == ''){w = that.width; } else {w = obj.cutwid; }スケール= w / h; h = w / scale; // canvas var canvas = document.createelement( 'canvas'); var ctx = canvas.getContext( '2d'); $(canvas).attr({width:w、height:h}); ctx.drawimage(that、0、0、w、h); // base64 base64 = canvas.todataurl( 'image/jpeg'、obj.quality || 0.8); var result = {base64:base64}; // obj.success(result); }; };以上就是本文的全部内容、希望对大家的学习有所帮助、也希望大家多多支持武林网。