获取一个在 onLoad 之后独立执行的 JQuery 函数
是否可以通过将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 javascript,您可以加载图像并检查它何时完成加载。
这不是 JQuery,而只是普通的 JS,但它是相同的想法。目标是图像所在的位置。如果加载完成,该函数将返回 true,否则返回 false。一旦为真,就运行您的 JCrop 方法。
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.
最终运行了一个计时器:
ended up running a timer: