问题描述
我的页面中有一组链接,并且附加了facebox jQuery功能,以便每当按下链接时,它都会弹出一个漂亮的弹出窗口
I am having a set of Links in my page and I have attached the facebox jQuery functionality so that whenever a link is pressed, it will get a nice popup
<a href="coach_selector_popup?day=<%= day %>&hour=<%= hour %>" rel="facebox">
下面是我用于'facebox'ing的脚本.
Below is the script that I use for 'facebox'ing.
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery('a[rel*=facebox]').facebox()
})
</script>
以上工作正常.但是,当我响应一些AJAX调用再次渲染它时,该功能将丢失,这意味着当我单击链接时,我将重定向到页面,而不是面板弹出窗口.
The above is working fine. But when I render it again on response to some AJAX call, the functionality is getting lost, meaning when I click on the link I am redirected to a page instead of a facebox popup.
我知道我在重新粉刷时需要做一些事情,有人可以指出我正确的方向吗?
I know that I need to do something when I repaint, can someone point me to the right direction?
编辑:我正在像这样在控制器上进行部分渲染.
I am doing a render partial on my controller like this.
render(:partial => "grid_item" , :locals => {:day=>d, :hour=>h)
推荐答案
包括您在部分内容中提到的javascript代码.我猜测它将在加载时再次执行.我不确定document.ready事件是否在部分更新上触发,但我认为是的.
Include the javascript code you mentioned inside you partial. I am guessing it will be executed again when loading it. I am not sure if the document.ready event is triggered on a partial update, but i think it is.
假设您使用的是link_to_remote
或类似名称,还可以使用:complete
或:succes
选项添加您的JavaScript回调,例如像这样:
Assuming you are using a link_to_remote
or something similar, you could also use the :complete
or :succes
option to add your javascript callback, e.g. like this:
link_to_remote get_icon('remove'),
:url => {:action => "your_action", :id => @record},
:success => "jQuery('a[rel*=facebox]').facebox();" ,
:failure => "alert('It failed?')"
希望有帮助!
这篇关于jQuery-Facebox-从AJAX重新绘制后,弹出窗口无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!