我使用以下代码使用js上传和预览图像,当我从计算机中选择图像时,它会正确预览图像,但是当我尝试再次上传图像并单击“取消”时,它会删除之前选择的图像图像,但在Firefox中它没有。 ,铬可能有什么问题?
function readURL(input) {
jQuery("#image_view1").hide();
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
jQuery("#image_view").html("<img id='image_view' src='"+ e.target.result+"' alt='your image' style='width: 240px; height: 130px; '/></br>");
};
reader.readAsDataURL(input.files[0]);
}
}
Html:
<form action="" method="post" id="frmGallery" enctype="multipart/form-data" class="mediaSliderForm">
<div class="control-group clearfix"><h2>Add Image</h2></div>
<div class="control-group clearfix"><label>Title : </label><input type="text" name="title" class="required"></div>
<div class="control-group clearfix"><label>Category : </label>
<select class="required testimonialCategory" name="category">
<option value="">Select Category</option>
<?php foreach($categories as $category){
echo $cat_id == $category->term_id ? '<option value="'.$category->term_id.'" selected="true">'.$category->name.'</option>' : '<option value="'.$category->term_id.'">'.$category->name.'</option>';
}?>
</select>
</div>
<div class="control-group clearfix"><label>Image: </label> <input type="file" name="image" id="image" class="required" onchange="readURL(this);"></div>
<div class="control-group clearfix"><label> </label><div id="image_view" class="advImg"></div></div>
<input type="submit" class="btn btn-small btn-inverse" name="submit" value="Submit">
</form>