开发者

jquery alternatives to .load

I want to use jQuery to grab a file and load it into a div on a click command. I know that I can do this with load but....

I want to be able to regenerate the same content as many times without clearing the last instance of it. Can anyone recommend another jQuery call to 开发者_如何学Pythondo this?


You could load the content into a new element each time:

$('<div>').load('...').appendTo('#container');


$.fn.getMoreContent = function()
{
    var collection = this;

    $.ajax( {
        url: 'page.html',
        success: function( data )
        {
            collection.append( data );
        }
    } );

    return collection;
};

$( '#someDiv' ).getMoreContent();

Working example: http://jsfiddle.net/JAAulde/dyRjQ/2/

Or:

$( '#someDiv' ).append(
    $( '<div>' ).load( 'page.html' )
);

Working example: http://jsfiddle.net/JAAulde/dyRjQ/3/


Another way to display external files on web page, is to embed it. You can do something like that:

$("#target embed").attr("src","filename.pdf");

Your HTML should be similar to that:

<div id="target">
   <embed src="" width="500" height="375">
</div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜