Ao trabalhar em Shenzhen, você precisa de um usuário para fazer upload da função de visualização do Avatar! Procurei muitos deles online, mas não fiquei muito satisfeito. Ou é flash ou retorna o caminho da imagem após o upload do Ajax, ou é inutilizável. Felizmente, alguém escreveu uma função de pré -visualização de fotos neste projeto antes, e eu o tirei para fazer um disco aqui para facilitar o uso no futuro e para outros amigos necessitados!
O código é simples, como segue:
<! xmlns = "http://www.w3.org/1999/xhtml"> <head> <meta http-equiv = "content-type" content = "text/html; charset = utf-8"/> <trat> por: dragondean/html; script; setImagePreview (Avalue) {var doc Docobj = document.getElementById ("doc"); var imgobjpreview = document.getElementById ("visualize"); if (docobj.files && docobj.files [0]) {// sob firefox, definir o imgtribute imgobjpre 'bloco'; imgobjpreview.style.width = '150px'; imgobjpreview.style.height = '180px'; //imgobjpreview.src = docobj.files [0] .GetasDataurl (); // A versão do Firefox 7 ou acima não pode ser obtida usando o método getasDataurl () acima. Você precisa do seguinte método imgobjPreview.src = window.url.createObjecturl (docobj.files [0]);} else {// sob ie, use o filtro docobj.select (); var iMgsrc = document.selection.Createrange (). Text; variMagid = documentyByByByBy (documentyByByByBy.Selection.Creterange (). localImagid.style.width = "150px"; localImagid.style.Height = "180px"; // A captura de exceções de imagem impedirá os usuários de modificar o sufixo para forjar a imagem tente {localImagid.style.filter = "progid: dxxETransform.microsoft.alphaimageloader (sizingmethod = scale)"; localImagid.filters.item ("dIMAGETRANSFORM.MICOSOFT.ALPHAIMAGELOTER {). está incorreto, selecione novamente! "); retornar false;} imgobjPreview.style.display = 'None'; document.selection.Empty ();} retornar true;} </sCript> </ad Head> <body> <Table Cellaping =" 0 "Cellpadding =" 0 "> <tbody> <d Local> id = "visualizar" src = "http://blog.chuangling.net/public/images/top.jpg" style = "display: block; Largura: 150px; Altura: 180px; "> </div> </td> </tr> <tr> <td align =" center "style =" padding-top: 10px; "> <input type =" file "name =" file "id =" doc "onchange =" javaScript: setImagePreview (////</td>Os testes podem ser usados no IE8, FF12.0 e Google Chrome 28.0.1500.72!