2010-12-10 3 views
0

페이지에 colorbox를 사용하려고합니다. 각 섹션에는 ajax 페이지를 호출하고 응답 텍스트가 필요한 div에 표시되는 onclick 이벤트가 있습니다. colorbox 링크를 제외한 모든 것이 잘 작동합니다. 아약스를 통해 콘텐츠를 호출하면 링크가 컬러 박스에 표시되지 않습니다. 다음은 페이지가로드 될 때 나타나는 colorbox를 호출하는 코드입니다. 아약스를 통해 호출 된 링크에 컬러 박스가 나타나지 않습니다.

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

나는이 문제를 찾기 위해 시도했지만 모든 것이 jQuery를 아약스 호출되지에게 간단한 아약스 호출에 관련이 있습니다. 이 .live() 또는 리바 인 딩 메소드를 사용하는 방법을 조언하고 있습니다. 여기 내 아약스 호출 코드 :

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

질문을 올바르게 이해하면 pageload 이후 ajax를 통해 페이지에 콘텐츠를로드했습니다.

당신이 가지고있는 자바 스크립트는 페이지로드에있는 데이터에 대해서만 작동하므로, 페이지로드 및로드시로드되는 요소에서 작동하는 .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/

관련 문제