2010-12-10 53 views
0

称为链接我想一个网页,我有三个环节,每个都有其调用Ajax页面和响应文本在必要的div显示onclick事件上使用的颜色框。一切工作正常,除了彩盒链接。在我通过ajax调用内容后,链接无法显示colorbox。这里是我的代码来调用页面加载工作时的颜色框。彩盒没有出现通过Ajax

<p> 
$(document).ready( 
    function() 
    { 
     $(".editchecklist").colorbox({width:"50%", height:"35%", iframe:true, onClosed:function(){ location.reload(true); } });   
    } 
); 

我试图寻找这个问题,但一切都与jQuery ajax调用不是简单的ajax调用有关。建议使用.live()或rebind方法,我不知道如何以及在哪里使用它们。 这里是我的Ajax调用代码:

function getxmlhttp()  
{ 
    var xmlHttp = false; 
    if (window.XMLHttpRequest) 
    { 
     // If IE7, Mozilla, Safari, etc: Use native object 
     var xmlHttp = new XMLHttpRequest(); 
    }else 
    { 
     if (window.ActiveXObject) 
     { 
      // ...otherwise, use the ActiveX control for IE5.x and IE6 
      var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
     } 
    } 
    return xmlHttp; 
} 

function process_ajax2(phpPage, objID, getOrPost,clickedLink) 
{  
    xmlhttp = getxmlhttp(); 
    var obj = document.getElementById(objID); 
    if(getOrPost == "get") 
    {   
     xmlhttp.open("GET",phpPage); 
     xmlhttp.onreadystatechange = function() 
     {   
      if(xmlhttp.readyState == 4 && xmlhttp.status == 200) 
      { 
       document.getElementById('change_'+clickedLink).innerHTML = xmlhttp.responseText; 
      } 
     } 
     xmlhttp.send(null); 
    } 
} 

请告诉我如何,我会解决这个问题?

感谢你。

回答

2

,如果我正确地理解你的问题,你已经通过AJAX页面加载后加载的内容到页面。

您得到的JavaScript只适用于页面加载时存在的数据,因此您需要做的就是使用.live(),它可用于在加载页面时以及之后加载的元素。

(注:我不知道你在想什么页面来电来访 - 所以我假设它在连结href中)

像这样的东西应该工作

$(function(){ 
    $(".editchecklist").live('click',function(e){ 
     e.preventDefault(); 
     $.colorbox({ 
       width:"50%", 
       href:$(this).attr('href'), 
       height:"35%", 
       iframe:true, 
       onClosed:function(){  
        location.reload(true); 
       } 
     }); 
    }); 
}); 

更多jQuery的生活http://api.jquery.com/live/