效果如下 :
html:
<dv> <div id = "showotherImage"> </div> <span id = "openIdcardimg"> <span> </span> <input type = "file" id = "Other_inputFile" name = "reasonimg"/> </span> </div>
.basicinfo .item {padding: .5rem .5rem 0; Border-top: .3rem solid #eeeeee;}. BasicInfo li {overflow: tersembunyi; margin-bottom: .5rem; garis-tinggi: 2.1rem; Border-Bottom: 1px solid #e3e3e3;}. BasicInfo li: Last-Child {Border-Bottom: None;}. Input BasicInfo [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; Line-Height: 3rem; Ukuran font: 3rem; margin-bottom: .5rem;}. BASICInfo .otherpic img {margin: 0 .5rem .5rem 0; Lebar: 3rem; Tinggi: 3rem; Vertical-Align: Top; BORDER: 1PX SOLID #DDD;}. BASICINFO .YY_INPUTFILE {Posisi: Absolute; TOP: 0; Kiri: 0; Lebar: 3rem; Tinggi: 3rem; opacity: 0;}. BasicInfo .aboutpic {margin-bottom: .5rem; Line-Height: 1.5rem; }JS:
var img_arr = array baru (); // 相关图片 $ (halaman) .on ('ubah', '#Other_inputfile', function () {$ (this) .ResizeImage ({itu: ini, cutwid: '', kualitas: 0.6, limitwid: 710, function: data) {var len = $ ('#showotherimage'). img = '<div style = "float: left;">' + '<img src = "' + img_arr [len] + '">' + '<span sid = "' + len + '" id = "Other_img _' + Len. 9) {$ ('#OpenIdCardimg'). // 删除相关图片 $ (halaman) .on ('klik', '. DeletedImages', function () {var sid = $ (this) .attr ('sid'); img_arr.splice (sid, 1); $ (this) .parent (). Remove (); $ ('#showothimage'). Html (''). img = '<div style = "float: left;">' + '<img src = "' + img_arr [i] + '">' + '<span sid = "' + i + '" id = "Other_Img_' + i + '" (span> (IMG> (IMG> (IMG> (IMG> (IMGRE; $ ('#OpenIdCardimg'). Show ();} else {$ ('#OpenIdCardimg'). Hide (); { * Lakukan sesuatu ... *} *}) * * */ $ .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 = gambar baru (); img.src = gumpalan; if (!/image /// w+/. test (obj.that.files [0] .type)) {$ .toast ("请上传图片!", 1000); mengembalikan false; } img.onload = function () {if (img.width <obj.limitwid) {$ .toast ('图片宽度不得小于' + obj.limitwid + 'px', 1000); mengembalikan false; } var that = this; // 生成比例 var w, skala, h = that.height; if (obj.cutwid == '') {w = that.width; } else {w = obj.cutwid; } skala = w / h; h = w / skala; // 生成 Canvas var canvas = document.createElement ('Canvas'); var ctx = canvas.getContext ('2d'); $ (canvas) .attr ({lebar: w, tinggi: h}); ctx.drawimage (itu, 0, 0, w, h); // 生成 base64 base64 = canvas.todataurl ('image/jpeg', obj.Quality || 0.8); var result = {base64: base64}; // 成功后的回调 obj.success (hasil); }; };以上就是本文的全部内容 , 希望对大家的学习有所帮助 , 也希望大家多多支持武林网。