2010-03-16 49 views
0

是否可以通過將其注入頁面來執行JQuery函數?它不能被附加到.ready函數。原因是用戶將通過iframe上傳圖片。我需要在顯示上傳圖像後執行JCrop。獲取一個jQuery函數執行onLoad之後和獨立於

echo "<script>$('#pictures_step1_right_bottom1', window.parent.document).html('<img id=\"cropbox\" src=\"../../box/" . 'THM' . $filenameAlt . '.jpg' . "\">');</script>"; 

echo "<script>jQuery(function(){jQuery('#cropbox').Jcrop();});</script>"; 

這是在處理圖像的iframe中執行的。然後它將它發送到主頁面。然而,這不起作用。

編輯:

導致跑定時器:

function checkPic() { 
    if($('#cropbox1').length != 0) { 
     jQuery(function() { 
      jQuery('#cropbox1').Jcrop(); 
     }); 
    } 
    timer(); // Check size again after 1 second 
} 

function timer() { 
    var myTimer = setTimeout('checkPic()', 3000); // Check size every 1 second} 
} 
+0

結束了運行的定時器: checkPic(); 功能checkPic() { \t如果($( '#cropbox1')。長度!= 0) \t { jQuery的(函數() \t { \t jQuery的( '#cropbox1')。Jcrop() ; \t}); } \t timer(); // 1秒後 \t} 功能定時器再次檢查尺寸() { \t變種myTimer = setTimeout的( 'checkPic()',3000); //每1秒檢查尺寸 } – lewicki 2010-03-16 05:43:07

回答

0

結束了運行的定時器:

checkPic(); 
function checkPic() 
{ 
    if($('#cropbox1').length != 0) 
    { 
     jQuery(function() { jQuery('#cropbox1').Jcrop(); }); 
    } 
    timer(); // Check size again after 1 second 
} 
function timer() 
{ 
    var myTimer = setTimeout('checkPic()', 3000); // Check size every 1 second 
} 
0

使用JavaScript可以加載圖像,並檢查時,它已經完成加載。

這不是JQuery,而只是普通的JS,但它是相同的想法。目標是圖像的位置。如果加載完成,函數將返回true,否則返回false。一旦這是真的,運行JCrop方法。

document.getElementById(target).complete