gpt4 book ai didi

javascript - 如何在选择图像时直接上传图像而不是在 JQuery 中按上传按钮

转载 作者:行者123 更新时间:2023-11-28 09:01:50 27 4
gpt4 key购买 nike

如何制作脚本来制作上传文件而不是按下面脚本中的上传按钮

详情:

在下方 <input type="file" id="pImage" name="image" class="upload-img" style="opacity:0">将显示上传的图像和 <input name="image" type="file"/>选择文件。和 <button>Upload</button>上传图片。

并且在 <input type="file" id="pImage" name="image" class="upload-img" style="opacity:0">它会选择文件,但我不想每次点击 Upload button 后都上传图片。如何在选择文件本身的同时使图片上传

HTML :

<div id="image" class="upload-img-span"></div>
<input type="file" id="pImage" name="image" class="upload-img" style="opacity:0">
<span class="upload-txt-span">Upload Img</span>
</div>
</td>
</tr>
<td colspan="4" align="left">
<input name="image" type="file"/>
<button>Upload</button>

脚本:

<script>
$("form#data").submit(function(){
var formData = new FormData($(this)[0]);
$.ajax({
url: 'globalimageupload',
type: 'POST',
data: formData,
async: false,
success: function (data)
{
$('#image').html(data);
console.log(data)
},
cache: false,
contentType: false,
processData: false
});
return false;
});
</script>

最佳答案

我不确定你到底想要什么,但看看 .trigger() 文档是 here .通过这个你可以触发任何其他事件,比如在你的情况下点击上传。希望它有帮助

关于javascript - 如何在选择图像时直接上传图像而不是在 JQuery 中按上传按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26879471/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com