[英]JQuery detect inserted image after submitting through form input type=“file”
我试图检测通过表单提交的图像,以便继续执行更多代码。 form input type="file"
图像后,使用form input type="file"
提交,然后使用jquery.form.js插件在页面中将其呈现为ajax。
我已经on.load
方法,但是它似乎只适用于文件代码中调用的图像。
$('.img_set').on('loaded', function (){
alert();
});
和:
$(".img_set").on('load', function() {
alert('I loaded!');
}).each(function() {
if(this.complete) $(this).load();
});
我也尝试过https://github.com/desandro/imagesloaded的插件,但是由于我希望工作而无法使用。
有什么方法可以检测到何时提交图像,而不是将其加载到页面的DOM中?
更新
上传处理程序
$('.photoimg').on('change', function (){
$('.db_result').html('<img src="images/loader.gif" />');
$('.imageform').ajaxForm({ target: $(this).closest('.child')}).submit();
$('.db_result').delay(500).queue(function(n) {
$(this).html('');
});
$('.child').on('load','.img_set', function() {
alert('new image loaded');
});
});
仍然不清楚您到底要什么,但假设文件已成功上传并且图像标签已添加到页面上的某个容器中,那么您应该能够通过委派load事件来检测何时已加载新图像使用选择器作为过滤器添加到容器中
$('#img_container').on('load','.img_set', function() {
alert('new image loaded');
});
使用委托允许处理程序将其应用于第一次呈现页面时加载的图像以及以后动态添加到页面中的元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.