用于设置文件路径值的html文件输入

用于设置文件路径值的html文件输入,html,file,input,Html,File,Input,我有输入文件上传html代码如下。我想设置输入文件值,然后在输入框中显示图像。但失败了。你知道为什么吗??有什么解决办法吗 <div class="mb10"> <input id="image2" name="image2" value="<?php echo $imageFile2;?>" class="file" type="file" accept="image/*"> <d

我有输入文件上传html代码如下。我想设置输入文件值,然后在输入框中显示图像。但失败了。你知道为什么吗??有什么解决办法吗

<div class="mb10">
<input id="image2" name="image2" value="<?php echo $imageFile2;?>" class="file" type="file" accept="image/*">
                                    <div id="uploadImgError2">
                                    </div>
                              </div>

$("#image2").fileinput({
    'showPreview' : true,
    'allowedFileExtensions' : ['jpg', 'png','gif', 'bmp'],
    'showUpload' : false,
    'maxFileCount':1,
    'maxFileSize': 10000000
});

HTML


您可以根据需要更改高度和宽度。

实际上,我仍然希望使用fileinput从网站获取图片并在file input标签中预览。可能吗???
<html>
<head>
<link class="jsbin" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
</style>
</head>
<body>
  <input type='file' onchange="readURL(this);" />
    <img id="image2" src="#" alt="image2" />
</body>
</html>
function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();

            reader.onload = function (e) {
                $('#image2')
                    .attr('src', e.target.result)
                    .width(150)
                    .height(200);
            };

            reader.readAsDataURL(input.files[0]);
        }
    }