For example, does $('#f').load('http://foobar.com #content');开发者_如何学运维
keep or strip out inline JavaScript such as onclick="..."
?
It throws away the script tags and does not execute the scripts when you use ".load()" in that form - with a selector attached to the URL like that.
See this jQuery bug report for more information.
When you use ".load()" with just a URL:
$('#f').load('http://foobar.com', function () { ... });
then it does run the scripts, though it still does strip them out. I think that the rationale for removing the scripts is that when manipulating the DOM by grabbing content and moving it around or replicating it, you generally don't want any stray script blocks to run again, but I'm not a jQuery contributor so I don't know for sure.
edit — Re-reading your question through my morning pre-caffeine haze I see that you're asking specifically about inline JavaScript in element attributes, like "onfoo" event handlers. Those are perfectly safe, as far as I know, no matter what sort of DOM wrangling you ask jQuery to do (other than explicitly affecting the attributes of course). What I wrote above pertains to embedded <script>
tags in the HTML markup.
精彩评论