获取一个在 onLoad 之后独立执行的 JQuery 函数

发布于 2024-08-25 10:33:21 字数 821 浏览 11 评论 0原文

是否可以通过将 JQuery 函数注入到页面中来执行它?它不能附加到 .ready 函数。原因是用户将通过 iframe 上传图像。我需要在显示上传的图像后执行 JCrop。

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}
}

Is is possible to execute a JQuery function by injecting it into the page? IT CAN'T be attached to the .ready function. The reason is that the user will be uploading an image via iframe. I need JCrop to execute after I display the uploaded image.

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>";

This is executed in the iframe that is processing the image. it then sends it to the main page. This does not work however.

EDIT:

Ended up running a timer:

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}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泡沫很甜 2024-09-01 10:33:21

使用 javascript,您可以加载图像并检查它何时完成加载。

这不是 JQuery,而只是普通的 JS,但它是相同的想法。目标是图像所在的位置。如果加载完成,该函数将返回 true,否则返回 false。一旦为真,就运行您的 JCrop 方法。

document.getElementById( target ).complete

Using javascript you can load an image and check when it has finished loading.

This is not JQuery but rather just normal JS but it's the same idea. With target being where the image is. The function will return true if it's done loading and false otherwise. Once it's true, run your JCrop method.

document.getElementById( target ).complete
毁我热情 2024-09-01 10:33:21

最终运行了一个计时器:

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 
}

ended up running a timer:

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 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文