原地址http://www.jb51.net/article/76651.htm
HTML代码
<label for="thumbnail" class="col-md-3 control-label">缩略图</label> <div class="col-md-6"> <input type="file" class="form-control" id="thumbnail" name="thumbnail"> </div>
JS代码
<script> function getObjectURL(file) { var url = null ; if (window.createObjectURL!=undefined) { // basic url = window.createObjectURL(file) ; } else if (window.URL!=undefined) { // mozilla(firefox) url = window.URL.createObjectURL(file) ; } else if (window.webkitURL!=undefined) { // webkit or chrome url = window.webkitURL.createObjectURL(file) ; } return url ; } $('#thumbnail').change(function() { var eImg = $('<img />'); eImg.attr('src', getObjectURL($(this)[0].files[0])); // 或 this.files[0] this->input $(this).after(eImg);}); </script>