我想允许用户在chrome扩展示例文件夹名称上上传图像(上传),并且没有提交按钮
<form action="/upload">
<input type="file" name="myimages" accept="image/*">
</form>
显示图像
<span class="AvGbtn" id="AvBgIds" style="background-image: url(Here i want to show upload images url
); background-size: 100% 100%;" oncontextmenu="return false">
</span>
答案 0 :(得分:4)
$( document ).ready(function() {
$( '#myimages' ).change(function() {
var filename = $('input[type=file]').val().replace(/C:\\fakepath\\/i, '');
$( '#myform' ).submit();
$( '#uploaded').append('<img src="/upload/' + filename + '"/>');
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="myform" action="/upload">
<input type="file" name="myimages" id="myimages" accept="image/*">
</form>
<div id="uploaded">
</div>
使用文件上载字段的onchange事件提交表单。
编辑:
增加了在表单下方的div中显示上传的图像的功能。
积分:Use jQuery to get the file input's selected filename without the path