简体   繁体   English

我可以在一个页面中有多个jquery .load()事件吗?

[英]Can I have multiple jquery .load() event in one page?

Is this possible? 这可能吗? I've got one jquery file that is loaded in every page that uses the .load() event, but then a few select pages also require some specific jquery stuff where I'd like to use .load() again. 我有一个jquery文件加载到每个使用.load()事件的页面中,但是一些选择页面也需要一些特定的jquery东西,我想再次使用.load()。 Thanks for reading. 谢谢阅读。

Yep, that's no worries. 是的,这不用担心。

The events will run in the order they were defined: 事件将按照定义的顺序运行:

$(function() {
  $('body').append('<span>A</span>');
});
$(function() {
  $('body').append('<span>B</span>');
});
$(function() {
  $('body').append('<span>C</span>');
});

The above would append "ABC" to the page. 上面会在页面上附加“ABC”。

Interestingly, if you use the long-hand method, it completes in a different order: 有趣的是,如果你使用长手法,它会以不同的顺序完成:

$(function() {
  $('body').append('<span>A</span>');
});
$(document).ready(function() {
  $('body').append('<span>B</span>');
});
$(function() {
  $('body').append('<span>C</span>');
});

This outputs "ACB" 输出“ACB”

Even more confusingly, if you only use the longhand, then it appears as though the first handler runs last and the rest in order: 更令人困惑的是,如果你使用了longhand,那么好像第一个处理程序最后运行而其余处理顺序如下:

$(document).ready(function() { /* A */ });
$(document).ready(function() { /* B */ });
$(document).ready(function() { /* C */ });
$(document).ready(function() { /* D */ });
$(document).ready(function() { /* E */ });
// BCDEA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在一页上具有多种jQuery按钮样式? - How can I have multiple jQuery button styles on one page? 如何有一个包含多个多个div的div可能是4-6-8我如何使用Jquery使它们适合页面加载 - How can have a div which contain multiple multiple div it may 4-6-8 how can i fit them on page load using Jquery 如何在一页上具有此jQuery图像幻灯片效果的多个实例 - How can I have multiple instances of this jQuery image slide effect on one page 如何在一个页面上有两个不同的变量? (JQuery的) - How can I have two of these on one page with different variables? (JQuery) 如何在同一页面上加载多个版本的jQuery插件? - How can I load multiple versions of a jQuery plugin on the same page? 如何在一页上有多个选项卡式框 - how can I have multiple tabbed boxes on one page 如何使用jquery在一个不同的窗口中加载多个选项卡? - How can I load multiple tabs in one different window with jquery? 我可以为多个JQuery手风琴使用一个Javascript函数吗? - Can I have one Javascript function for multiple JQuery accordions? 在加载页面元素之前,必须在jquery中使用哪个事件进行调用? - Which event I have to use in jquery to get called before my page elements load? 如何在一页JQuery上使用多个切换? - How can I use multiple toggle on one page JQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM