对jquery .load()感到好奇 [英] curious about jquery .load()

查看:90
本文介绍了对jquery .load()感到好奇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读 jQuery .load()文档后,在脚本执行"部分中,它说这个:

After reading the jQuery .load() documentation, at the "Script Execution" section, it said this:

脚本执行

使用不带后缀选择器的URL调用.load()时 表达式,在脚本被编写之前,将内容传递给.html(). 删除.这将在脚本块被丢弃之前执行它们.

When calling .load() using a URL without a suffixed selector expression, the content is passed to .html() prior to scripts being removed. This executes the script blocks before they are discarded.

  1. 关于短语在删除脚本之前",这是否意味着脚本将被删除而不添加到DOM?只是HTML会传递到文档并在DOM中更新?

  1. Regarding the phrase "prior to scripts being removed", does this mean that the script will be removed and not added to the DOM? That only the HTML will be passed to document and updated in the DOM?

关于短语这在脚本块被丢弃之前先执行",这真的意味着脚本先执行然后被丢弃,还有没有办法让我们稍后调用它?

Regarding the phrase "this executes the script blocks before they are discarded", does it really mean that the script executes and then is discarded, and there is no means for us to call it later?

即使将脚本传递到文档,如果DOM没有更新,我们以后也不能调用它,可以吗?

Even if the scripts are passed to the document, if the DOM is not updated, we can not call it later either, can we?

如果以上问题的所有答案都是肯定的,则意味着使用.load()加载javascript文件只能在.load()完成加载后立即执行,对吗?而且没有必要在.load()之后再次调用该脚本,因为该脚本已被丢弃并消失了?

If all the answers to the questions above are yes, that means loading a javascript file using .load() can only be an instant execution after .load() is finished loading, right? And that there is no mean to call that script again after .load(), because it is discarded and gone?

推荐答案

加载了.load()的JavaScript的工作原理与<script></script>标记中的常规内联JavaScript完全一样.

JavaScript loaded with .load() works exactly like usual inline JavaScript from <script></script> tags.

要从已加载的JavaScript代码段中获取一些结果,您可以创建一些对象或属性,定义函数等.例如,可以以这种方式加载jQuery插件.

To get some results from the loaded JavaScript snippet you can create some objects or properties, define functions etc. For example, a jQuery plugin can be loaded this way.


请注意,如果存在带后缀的选择器,则将不会执行任何脚本.


Notice, that if a suffixed selector is present, than no scripts will be executed.

这篇关于对jquery .load()感到好奇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆