且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在ajax调用之后加载脚本的位置在哪里?

更新时间:2023-12-05 10:58:16

添加的jQuery代码到DOM的HTML总是删除< script> 标记。它运行它们然后将它们抛弃。

The jQuery code that adds HTML to the DOM always strips out <script> tags. It runs them and then throws them away.

该行为的一个例外是当你使用允许加载片段的hack使用$ .load()时页面:

An exception to that behavior is when you use "$.load()" with the hack that allows you to load a fragment of a page:

$.load("http://something.com/whatever #stuff_I_want", function() { ... });

在这种情况下,脚本将被剥离并且评估/运行。

In that case, the scripts are stripped and not evaluated/run.