如果您需要将内容加载到同一Colorbox中而不是打开新实例,那么我将首先确保打开Colorbox的事件处理程序上下文是互斥的,并且不要钩接到Colorbox中的’open_ajax’元素上。
像这样:
<script type="text/javascript"> $(document).ready(function(){ $("a[rel='open_ajax']:not(#colorbox a[rel='open_ajax'])").live('click', function() { $.colorbox({ href:$(this).attr('href') }); return false; }); });</script>如果上述方法不起作用,请尝试使选择器更具体/唯一。
然后将新内容中的AJAX直接放入您已经打开的Colorbox中。
像这样:
$('#cboxLoadedContent a[rel="open_ajax"]').live('click', function(e){ // prevent default behaviour e.preventDefault(); var url = $(this).attr('href'); $.ajax({ type: 'GET', url: url, dataType: 'html', cache: true, beforeSend: function() { $('#cboxLoadedContent').empty(); $('#cboxLoadingGraphic').show(); }, complete: function() { $('#cboxLoadingGraphic').hide(); }, success: function(data) { $('#cboxLoadedContent').append(data); } });});


