关于 jQuery 片段的问题

发布于 2024-08-23 07:34:57 字数 594 浏览 4 评论 0原文

好的,所以我正在使用 facebox 插件。给出的示例之一是触发弹出窗口、触发微调器、执行 ajax 调用,当调用返回时用结果替换微调器。代码在这里 有

jQuery.facebox(function($) { 
 $.get('blah.html', function(data) { $.facebox(data) })
})

几个问题。

  1. 我认为 jQuery$ 变量是同一件事,只有当与其他库存在命名冲突时才使用 jQuery 。在此示例中,作者调用 jQuery.facebox 并传入一个以 $ 作为参数的函数。我是否误解了两者之间的区别?
  2. 在 .get 回调中,我们调用 $.facebox 是在 jquery 全局上下文中的 $ ,还是传递给外部函数的变量?

感谢您的澄清:-)

Ok, so I am using the facebox plugin. One of the examples given is to trigger the popup, trigger a spinner, do an ajax call, when the call returns replace the spinner with the results. Code is here

jQuery.facebox(function($) { 
 $.get('blah.html', function(data) { $.facebox(data) })
})

A few questions.

  1. I thought that the jQuery and $ variables were the same thing, and you use jQuery only when there are naming conflicts with other libraries. In this example, the author calls jQuery.facebox and passes in a function with $ as a param. Am I misunderstand the difference between the two?
  2. in the .get callback, we are calling $.facebox is $ in that context the jquery global, or is it the variable passed in to the outer function?

Thanks for the clarification :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我相信作者正在通过将 $ 传递给自身来清理(免于任何冲突)——第一个 jQuery 是为了确保它是 jQuery 做的,并且 jQuery 对象 $ 使它可以使用。只是一个预防措施。

I believe the author is sanitizing (freeing from any conflicts) $ by passing it to itself--the first jQuery is to make sure it's jQuery doing it, and the jQuery object $ makes it okay to use. Just a precaution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文