2009-08-21 3 views
0

내 메인 페이지에서 아약스 호출을하고 내 페이지의 DIV에 전체 페이지 내용을로드하는이 jquery 코드가 있습니다. 초jquery json 결과의 결과를 어떻게 만들 수 있습니까?

<!-- Auto update/look for NEW notifications --> 
<script type='text/javascript'> 
$(document).ready(function(){ 
    var updatenotification = function(){ 
      $('#notificationcontainer') 
       .load('/modules/member/home/notifications.inc.php') 
       .fadeIn("slow"); 
    }; 
    var auto_refresh = setInterval(function(){updatenotification();}, 5000); 
    updatenotification(); 
}); 
</script> 
<!-- ENDS HERE --> 


<div id="#notificationcontainer"></div> 

나는 그렇게 내가 대신 내 notification.inc.php 출력 JSON 문자열을 걸려 라 앞뒤로 적은 데이터를 전송하기 위해이 생각을 변경하고자하고있다. 나는이 값들을 갖도록 만들 것이다.

항목 2 = 1

item5 = 1로 표시됩니다 두 항목이 통지, 6 개 항목의 총이있다하지만 난 JSON 문자열에있는 사람 만 포함됩니다

1이 I Json 문자열을 읽을 코드를 만들고 싶습니다. 1은 jquery가 해당 항목을 페이지에 표시해야 함을 의미합니다. 페이지에 숨겨져있는 모든 항목을 페이지에 숨겨야합니다. 1 jquery가 표시되도록해야합니다. 또한 이름은 내가이 작업을 수행 할 수있는 방법 그들은 모두

<style type="text/css"> 
#item1{ 
    display:none; 
} 
#item2{ 
    display:none; 
} 
#item3{ 
    display:none; 
} 
#item4{ 
    display:none; 
} 
#item5{ 
    display:none; 
} 
#item6{ 
    display:none; 
} 
</style> 


<div id="notificationhead">Notifications</div> 
<div class="notificationlink" id="item1"><a href="">Testing 1</a></div> 
<div class="notificationlink" id="item2"><a href="">Testing 2</a></div> 
<div class="notificationlink" id="item3"><a href="">Testing 3</a></div> 
<div class="notificationlink" id="item4"><a href="">Testing 4</a></div> 
<div class="notificationlink" id="item5"><a href="">Testing 5</a></div> 
<div class="notificationlink" id="item6"><a href="">Testing 6</a></div> 

을 변경됩니다 단지 일반적인입니까?

답변

1

귀하의 질문에 대한 해결책은 아니지만 다른 조언을 구하십시오. 표시 할 div에 추가 클래스 (예 : "visible")를 추가하고 해당 CSS를 display: block, 클래스를 display: none으로 설정하여 CSS를 단순화 할 수 있습니다. 각 div에서 ID를 수동으로 설정하는 오버 헤드를 없앨 수 있습니다.

HTML에 여러 클래스가 허용되므로 class="notificationlink visible first-child extended"과 같은 결과를 얻을 수 있습니다. 완벽하게 유효합니다.

관련 문제