2010-03-16 48 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