开发者

Execute inline JS and CSS after Pageload via AJAX (jQuery)

I have Problems after开发者_如何学C loading a whole new page via Ajax to get all inline JS and CSS executed. The result of this call is a whole new page including , i want to replace with current content. Does JQuery provide functionality to execute all scripts after success of an Ajax Call? My first idea was to select all script tags from result and append it to the body. Second idea was to selecet all script tags and execute their contents with eval(). Thx for helping..


When you call .html() in jQuery to insert the returned HTML into the page, all inline scripts will be executed. For example: http://jsfiddle.net/Paulpro/LX58E/ Or:

var html = '<script type="text/javascript"> alert(\'Hi\'); <\/script>';
// Execute the script twice
$('body').html(html+html);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜