将 Facebox 应用于使用 Ajax 显示的链接
我有一个小问题。所以我有这个页面,在页面加载完成后使用 jQuery Ajax 加载动态内容。页面顶部有一个名为“添加新闻”的链接。当您单击该链接时,会弹出一个脸箱。该链接是静态的,仅在页面顶部显示一次。它的标签是:
<a href="linktopage" rel='facebox[.xhr]'>Add News</a>
动态页面(从 Ajax 加载)列出了数据库中所有现有的新闻。它们被标记为:
<a href="linktonews?id=1" rel='facebox[.xhr]'>News 1</a>
<a href="linktonews?id=2" rel='facebox[.xhr]'>News 2</a>
<a href="linktonews?id=3" rel='facebox[.xhr]'>News 3</a>
等等...单击其中一个新闻项目,打开一个脸箱,您可以在其中查看/编辑新闻。
每次添加新的新闻项目时,动态内容都会重新加载,而无需刷新页面。
当加载主索引页面时,facebox 的定义是使用 $('a[rel*=facebox]').facebox();
实例化的。
现在我的问题是这个 $('a[rel*=facebox]').facebox();
不适用于使用ajax加载的新闻内容。因此,点击这些链接不会打开脸箱。我怎样才能实现这个目标?
提前致谢。
I have a small problem. So I have this page that loads dynamic content using jQuery Ajax after the page is done loading. On the top of the page is a link called "Add News". When you click on that Link, a facebox pops open. This link is static and is only displayed once on the top of the page. Its labeled:
<a href="linktopage" rel='facebox[.xhr]'>Add News</a>
The dynamic page (loaded from Ajax) lists all the existing news in the DB. They are labeled:
<a href="linktonews?id=1" rel='facebox[.xhr]'>News 1</a>
<a href="linktonews?id=2" rel='facebox[.xhr]'>News 2</a>
<a href="linktonews?id=3" rel='facebox[.xhr]'>News 3</a>
and so on... Clicking one of the news items, open a facebox where you can view/edit the news.
Every time a new news item is added, the dynamic content reloads without refreshing the page.
The definition of facebox is instantiated using $('a[rel*=facebox]').facebox();
when the main index page is loaded.
Now my problem is that this $('a[rel*=facebox]').facebox();
does not apply to the news content loaded using ajax. So clicking on those links does not open a facebox. How can I achieve this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,所以我开始查看 GitHub 中的拉取请求,发现:
https://github.com/dator/facebox/commit/5ce6a75927d81b9fff1eeff9b933f0ad93f12801
by Dator(支持他!:D)
因为看来拉取请求尚未合并,但我刚刚更改了我的facebox.js 中的那行代码效果很好:D
希望这会有所帮助:)
I had the same problem so I started looking at the pull requests in GitHub and found:
https://github.com/dator/facebox/commit/5ce6a75927d81b9fff1eeff9b933f0ad93f12801
by Dator (props to him! :D)
As it seems that the pull request isn't merged yet I just changed that line in my facebox.js and it works great :D
Hope this helps :)