jQuery触发页面加载操作(jQuery triggering action on page load)

编程入门 行业动态 更新时间:2024-10-26 17:32:59
jQuery触发页面加载操作(jQuery triggering action on page load)

我目前有以下代码将灯箱添加到具有rel="facebox"链接。

$(document).ready(function() { $('a[rel*=facebox]').facebox(); });

这很有效,直到页面加载时间太长。

如何在文档加载之前应用此功能? 理想情况下,我想首先调用.facebox()函数,当DOM加载时,它会搜索任何带有rel="facebox"链接并应用该函数。

有点像.on()函数,但没有事件。

那有意义吗? 提前致谢!

I currently have the following code to add a lightbox to links that have rel="facebox".

$(document).ready(function() { $('a[rel*=facebox]').facebox(); });

This works well until a page takes a little too long to load.

How do I apply this before the document has loaded? Ideally I'd like to call the .facebox() function first and as the DOM loads, it searches for any link with rel="facebox" and applies the function.

Kind of like the .on() function but without an event.

Does that make sense? Thanks in advance!

最满意答案

这里有几个链接可能有助于解决这个问题......

在DOM准备好之前使用元素并使用JavaScript检测DOM节点插入...

Found my solution by doing the following:

$(document).on('click', 'a[rel*=facebox]', function() { $.facebox({ ajax: $(this).attr('href') }); return false; });

Hope that helps somebody.

更多推荐

本文发布于:2023-08-04 16:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417782.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   页面   操作   jQuery   load

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!