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>

HTML5实现图片选择并预览_第1张图片

你可能感兴趣的:(HTML5实现图片选择并预览)