简体   繁体   English

为什么onload =“function”有效,jquery.load没有?

[英]Why onload=“function” works and jquery.load doesn't?

i'm loading a SVG file to a <object> , and one of my problems now, is to figure out why the atribute inside the <object onload="function" /> works, but obj.load(function(){}); 我正在将一个SVG文件加载到<object> ,现在我遇到的一个问题是弄明白为什么<object onload="function" /> obj.load(function(){});有效,但是obj.load(function(){}); doesen't doesen't

Are they different? 他们不一样吗? load can only be performed in Images, and in the body? 加载只能在图像和身体中执行?

Thanks 谢谢

EDIT: Here is a part of the code: 编辑:这是代码的一部分:

var cont = $('<div class="file" >'+file.file_name+'</div>'); 

        var render = $('<object id="file_'+file.id+'" data="/while1/pcbsfiles/view/'+file.id+'" type="image/svg+xml"/></object>');
        cont.append(render);
        render.css('visibility', 'hidden');

        cont.load(function(){
            //
            render.removeClass('position');
            render.removeClass('left');
            alert("aaaaaa");
            render.fadeIn();
        });

I tried with cont.load , render.load , $('#file_'+file.id).load also 我尝试使用cont.loadrender.load$('#file_'+file.id).load

I believe the .load declaration needs to be directly after you create the object, before you append it to another object. 我相信.load声明需要在创建对象之后直接将其附加到另一个对象之前。 I can't give specifics as to why, but I've had a similar problem before. 我不能详细说明原因,但我之前遇到过类似的问题。

Try something more like this: 尝试更像这样的东西:

var cont = $('<div class="file">'+file.file_name+'</div>');
$(cont).load(function(){
    var $render = $(render);
    $render.removeClass('position');
    $render.removeClass('left');
    alert("aaaaaa");
    $render.fadeIn();
});

var render = $('<object></object>');
$(render).attr('id', 'file_'+file.id)
    .attr('data', '/wihlte1/pcbsfiles/view/'+fild.id)
    .attr('type', 'image/svg+xml')
    .css('display', 'none');
$(cont).append(render);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM