现在的位置: 首页 > 综合 > 正文

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

2012年09月11日 ⁄ 综合 ⁄ 共 1078字 ⁄ 字号 评论关闭

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

 

抱歉!评论已关闭.