簡體   English   中英

jQuery通過表單輸入type =“ file”提交后檢測插入的圖像

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM