我正在使用一个表单提交ajax调用触发ceebox的函数的drupal站点。 drupal php函数的代码如下:
$commands = array();
$html = '<a title="" style="display:none;" href="/subscribe" class="ceebox" id="subscribe" rel="iframe width:500 height:350"></a>';
//attempt to remove already existing ceebox generated elements
$commands[] = ajax_command_replace('#subscribe','');
$commands[] = ajax_command_replace('#cee_iframeContent', '');
$commands[] = ajax_command_replace('#cee_title', '');
$commands[] = ajax_command_append('body', $html);
$commands[] = ajax_command_invoke(NULL, 'subscribeOpen', array('subscribe'));
return array('#type' => 'ajax', '#commands'=>$commands);
drupal函数调用的Javascript:
(function($) {
$.fn.subscribeOpen = function(data) {
$('#subscribe').ceebox().trigger('click');
};
})(jQuery);
这一切都按预期工作;即在iframe中调出包含ceebox的/订阅页面内容。当我点击ceebox上的关闭链接或单击要关闭的背景时,它会第一次关闭。当我点击订阅链接以触发drupal ajax和ceebox调用时,它会添加一个额外的关闭链接,一个额外的'Item 1 of 1'标题和一个额外的iFrame窗口。每次单击关闭时重复此操作,然后触发无限添加功能。我试图将unbind('#ceebox')添加到#subscribe元素以及jQuery unique()方法的各种组合无济于事。有人可以解释如何取消绑定/删除这些重复的ceeboxes吗?
答案 0 :(得分:2)
我通过查看jquery.ceebox.js文件找到了这个,并发现intialise函数在其上运行了live()方法。
这将导致各种奇妙的问题,因为它应该只在元素上调用一次。上面的代码在触发ceebox时会多次调用live(),因此我建议你替换jquery.ceebox.js的第374行:
$(elem).live("click", function(e){
阅读:
$(elem).bind("click", function(e){