简体   繁体   English

jQuery-Facebox-从AJAX重新绘制后,弹出窗口无法正常工作

[英]jQuery-Facebox - Popup is not working after repaint from AJAX

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 我的页面中有一组链接,并且附加了facebox jQuery功能,以便每当按下链接时,它都会弹出一个漂亮的弹出窗口

<a href="coach_selector_popup?day=<%= day %>&hour=<%= hour %>" rel="facebox">

Below is the script that I use for 'facebox'ing. 下面是我用于“ facebox”处理的脚本。

<script type="text/javascript">
  jQuery(document).ready(function($) {
    jQuery('a[rel*=facebox]').facebox()
  })
</script>

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. 但是,当我响应一些AJAX调用再次渲染它时,该功能会丢失,这意味着当我单击链接时,我将重定向到页面而不是出现在面板上的弹出框。

I know that I need to do something when I repaint, can someone point me to the right direction? 我知道我在重新粉刷时需要做一些事情,有人可以指出我正确的方向吗?

Edit: I am doing a render partial on my controller like this. 编辑:我正在像这样在我的控制器上做部分渲染。

render(:partial => "grid_item" , :locals => {:day=>d, :hour=>h)

Include the javascript code you mentioned inside you partial. 在部分内容中包含您提到的javascript代码。 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. 我不确定document.ready事件是否在部分更新上触发,但我认为是。

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, eg like this: 假设您使用的是link_to_remote或类似的名称,也可以使用:complete:succes选项添加您的JavaScript回调,例如:

link_to_remote get_icon('remove'), 
   :url => {:action => "your_action", :id => @record},
   :success => "jQuery('a[rel*=facebox]').facebox();" , 
   :failure => "alert('It failed?')"

Hope it helps! 希望能帮助到你!

您必须在添加新元素后再次调用.facebox() 。在ajax上使用回调函数...

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM