我想允许用户在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>
$( 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