读书人

struts2图片上传预览,该如何解决

发布时间: 2011-12-29 22:09:38 作者: rapoo

struts2图片上传预览
在IE和火狐下如何实现图片上传和预览

[解决办法]

HTML code
<html>     <head>         <title>get file input full path</title>     <script language='javascript'>         function getFullPath(obj)         {             if(obj)             {                 //ie                 if (window.navigator.userAgent.indexOf("MSIE")>=1)                 {                     obj.select();                     return document.selection.createRange().text;                 }                 //firefox                 else if(window.navigator.userAgent.indexOf("Firefox")>=1)                 {                     if(obj.files)                     {                         return obj.files.item(0).getAsDataURL();                     }                     return obj.value;                 }                 return obj.value;             }         }     </script>     </head>     <body>         <input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />     <img id="img" />     </body> </html> 

读书人网 >J2EE开发

热点推荐