- <!DOCTYPE html>
- <html>
- <head>
- <script src1="jQuery.js"></script>
- <meta charset=utf-8 />
- <title>JS Bin</title>
- <style>
- </style>
- </head>
- <body>
- <input type='file' onchange="readURL(this);" id='changeimg'/>
- <img id="img_prev" src1="#" alt="your image" />
- </body>
- <script>
- $(function(){
- $('#img_prev').CSS('display','none');
- $('#changeimg').change(function(){
- $('#img_prev').css('display','block');
- });
- })
- </script>
- <script>
- function readURL(input) {
- if (input.files && input.files[0]) {
- var reader = new FileReader();
- reader.onload = function (e) {
- $('#img_prev')
- .attr('src', e.target.result)
- .width(150)
- .height(200);
- };
- reader.readAsDataURL(input.files[0]);
- }
- }
- </script>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/2312201615209.html
来源: http://www.codesnippet.cn/detail/2312201615209.html