<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>网页特效 上传图片预览</title>
<script language="网页特效"> 
function showimage(fileuploadid, imgid) {
    if (document.getelementbyid(fileuploadid).value != "") {
        document.getelementbyid(imgid).style.display = "block"
        document.getelementbyid(imgid).src = getpath(document.getelementbyid(fileuploadid));
    }
 }
 
 function getpath(obj) {
    if (obj) {
        if (window.navigator.useragent.indexof("msie") >= 1) {
            obj.select(); return document.selection.createrange().text;
        }
        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>
<form enctype="multipart/form-data">
  <label>
<input type="file" name="file" id="fid"  onmouseo教程ut="showimage('fid','viewimg');">
</label>
<input name="" type="button" value="提交">
</form>
<img src="" id="viewimg">
</div>
</body>
</html>
这里的onmouseo教程ut是什么意思?

解决方案 »

  1.   

    晕,你把教程2个字去掉
    onmouseout=
      

  2.   

    onmouseo教程ut
    改为
    onmouseout这更说明:网上粘贴下来的代码并不是都能直接使用的
      

  3.   

    <input type="file" name="link_pic" class="fl file_input" id="tupian" />
      <input type="button" class="upload_btn fl" value="上传" onclick="yulan2('tupian');" />
    <tr style="display:none" id="image">
      <td width="100px">&nbsp;&nbsp;图片预览</td>
      <td><div id="image2"></div></td>
    JS代码如下:<script>
    function yulan2(str){
    var obj = document.getElementById(str);
    var str = getPath(obj);
    document.getElementById('image').style.display="";
    var liulanqi = getOs();
    if(liulanqi=="Safari")
    {document.getElementById('image2').innerHTML = "该款浏览器无法正常显示待上传的图片,但不会影响图片的正常上传,若要显示待上传的图片,推荐使用IE浏览器登录本系统!";}
    else
    {document.getElementById('image2').innerHTML = "<img src='" + str + "' />";}
    }
    function getOs()   
    {   
      var OsObject = "";   
      if(navigator.userAgent.indexOf("MSIE")>0) {   
      return "MSIE";   
      }   
      if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){   
      return "Firefox";   
      }   
      if(isSafari=navigator.userAgent.indexOf("Safari")>0) {   
      return "Safari";   
      }   
      if(isCamino=navigator.userAgent.indexOf("Camino")>0){   
      return "Camino";   
      }   
      if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){   
      return "Gecko";   
      }   
    }  //获取以下即为完整客户端路径
    function getPath(obj) {
    if(obj){
    if(window.navigator.userAgent.indexOf("MSIE") >= 1) {
    obj.select(); return document.selection.createRange().text;
    }else if(window.navigator.userAgent.indexOf("Firefox") >= 1) {
    if (obj.files) {
    return obj.files.item(0).getAsDataURL();
    }
    return obj.value;
    }
    return obj.value;
    }
    }  为什么Firefox可以预览。但是IE却显示X?求完整代码
      

  4.   

    这样试试
    <table>
    <tr>
    <td colspan='2'>
    <input type="file" name="link_pic" class="fl file_input" id="tupian" />
    <input type="button" class="upload_btn fl" value="上传" onclick="yulan2('tupian');" />
    </td>
    </tr>
    <tr style="display:none" id="image">
      <td width="100px">&nbsp;&nbsp;图片预览</td>
      <td><div id="image2"></div></td>
    </tr>
    </table>
    <SCRIPT LANGUAGE="JavaScript">
    function yulan2(str){
    var obj = document.getElementById(str);
    var str = getPath(obj);
    document.getElementById('image').style.display="";
    var liulanqi = getOs();
    if(liulanqi=="Safari")
    {document.getElementById('image2').innerHTML = "该款浏览器无法正常显示待上传的图片,但不会影响图片的正常上传,若要显示待上传的图片,推荐使用IE浏览器登录本系统!";}
    else
    {document.getElementById('image2').innerHTML = "<img src='" + str + "' />";}
    }
    function getOs()  
    {  
      var OsObject = "";  
      if(navigator.userAgent.indexOf("MSIE")>0) {  
      return "MSIE";  
      }  
      if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){  
      return "Firefox";  
      }  
      if(isSafari=navigator.userAgent.indexOf("Safari")>0) {  
      return "Safari";  
      }  
      if(isCamino=navigator.userAgent.indexOf("Camino")>0){  
      return "Camino";  
      }  
      if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){  
      return "Gecko";  
      }  
    }  //获取以下即为完整客户端路径
    function getPath(obj) {
    if(obj){
    if(window.navigator.userAgent.indexOf("MSIE") >= 1) {
    obj.select(); return document.selection.createRange().text;
    }else if(window.navigator.userAgent.indexOf("Firefox") >= 1) {
    if (obj.files) {
    return obj.files.item(0).getAsDataURL();
    }
    return obj.value;
    }
    return obj.value;
    }
    }  
    </script>
      

  5.   

    现在知道为什么IE不能正常显示图片。是因为IE7/8都不能直接使用本地路径显示图片。那我应该怎样改呢(滤镜)