zoukankan      html  css  js  c++  java
  • [转]文件浏览直接显示[兼容IE,FireFox]

    转自:http://www.cnblogs.com/shawker/archive/2009/03/27/1423386.html


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title></title>

    <script> 

    function $(o) {

            
    return document.getElementById(o);

    }

    function SeePic(img,f){

            
    var i = $(img);

            
    var f = $(f);

            
    if (f.value != "") {

                    
    if (f.value.indexOf("http://">= 0) {

                            i.src 
    = f.value;

                    } 
    else {

                          
    if (!window.event)

                          {

                             
    var data = f.files.item(0).getAsDataURL();

                             i.src 
    = 'data:' + data;

                          }

                          
    else

                           i.src 
    = 'file:///'+f.value;

                    }

                    i.style.display 
    = "block";

                    
    return;

            }

            i.style.display 
    = "none";

     



    </script> 

    </head>

    <form id='frm1' name='frm1'> 

    <div><input type='file' name='upfile' id='upfile' onChange="SeePic('img', 'upfile');"></div> 

    <div><image src='' id='img' name='img' style="display:none;"> </div>

    </form> 

    </body>

    </html>

     保存成utf-8格式,直接运行即可。

  • 相关阅读:
    Div+CSS 布局
    Windows Mobile 参考:
    Linux export的作用
    CSS(2)基本语法
    HTML(6)超链接
    HTML(5)常用的格式标签
    HTML(8)表格
    CSS(1) CSS简介
    HTML(7)图像、背景和颜色
    HTML(10)框架
  • 原文地址:https://www.cnblogs.com/wangpei/p/1423402.html
Copyright © 2011-2022 走看看