图片浏览直接显示[兼容IE,FireFox]

<!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=gb2312" />

<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>

 

posted @ 2009-03-27 17:45  潇客的技术博客  阅读(1557)  评论(6编辑  收藏  举报