HTML5实现图片选择并预览

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="jquery-1.11.2.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $(function () {
                $("#fileupload").change(function () {
                    var reader = new FileReader();

                    reader.onload = function (e) {
                        $("#img1").attr("src",e.target.result);
                    }

                    reader.readAsDataURL($(this)[0].files[0]);
                })

            });
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <input id="fileupload" type="file" />
    <img id="img1" style="width:150px; height:90px;" />
    </form>
</body>
</html>

posted @ 2015-12-18 14:20  Franky2015  阅读(889)  评论(0编辑  收藏  举报