| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
- <title>上传图片预览功能</title>
- <!--
- <link rel="stylesheet" href="style.css" />
- -->
- <script type="text/javascript" src="/static/js/jquery-1.7.2.min.js"></script>
- <script type="text/javascript">
- $(function () {
- $("#pic").change(function () {
- if ($.browser.msie) {
- alert('ccc');
- $("#img0").attr("src", $(this).val())
- $("#info").text("当前选择的文件:" + $(this).val())
- } else {
- alert('ddd');
- $("#info").text("当前选择的文件:" + $(this).val())
- var objUrl = getObjectURL(this.files[0]);
- console.log("objUrl=" + objUrl);
- if (objUrl) {
- $("#img0").attr("src", objUrl);
- }
- }
- })
- //建立一個可存取到該file的url
- function getObjectURL(file) {
- var url = null;
- if (window.createObjectURL != undefined) {
- url = window.createObjectURL(file);
- } else if (window.URL != undefined) {
- url = window.URL.createObjectURL(file);
- } else if (window.webkitURL != undefined) {
- url = window.webkitURL.createObjectURL(file);
- }
- return url;
- }
- })
- </script>
- </head>
- <body>
- <form action="" name="form0" id="form0">
- <input type="file" name="pic" id="pic" class="file0"/>
- <a href="">选择图像</a>
- <span id="info"></span>
- <img src="" alt="" id="img0" width="100"/>
- </form>
- </body>
- </html>
|