2014-02-17 2 views
-3

메소드에서 Json 유형의 데이터를 가져 와서 닫기 버튼이있는 div 태그에 표시하는 스크립트를 작성했습니다. 닫기 버튼을 클릭하면 작동하지 않습니다! 내 스크립트는 다음과 같습니다.jquery 스크립트가 작동하지 않는 이유는 무엇입니까?

$(document).ready(function() { 
     $("#go").click(function() { 
      setInterval(function() { 
       $.ajax({ 
        type: "POST", 
        url: "WebForm2.aspx/GetMyBooks", 
        data: '{}', 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        success: function (response) { 

         for (var i = 0; i < response.d.length; i++) { 
          $("#pejiGrid").append("<div class='modal'><div style='float:left;'><span class='close'>X</span></div>" + response.d[i].BOOK_NAME + "<br/>" + response.d[i].BOOK_DESC + "</div><br/>"); 
         }; 
        }, 
       }); 
       $('.modal').hover(
        function() { 

         $(this).find('.close').delay(0).fadeIn(300); 

        }, 
        function() { 

         $(this).find('.close').delay(0).fadeOut(500); 
        }); 

      }, 5000); 
     }); 

     $('span.close').click(
      $(this).closest('div.modal').fadeOut(0) 
      ); 
     }); 

무엇이 문제입니까?

편집 :

$('.modal').hover(
        function() { 

         $(this).find('.close').delay(0).fadeIn(300); 

        }, 
        function() { 

         $(this).find('.close').delay(0).fadeOut(500); 
        }); 

일부 몸이 문제가 무엇인지 나에게 도움이 될 수 있습니다 내 호버 스크립트 내가 그것을 지연에 의해 닫기 버튼을 보여줍니다하지만 난 값을 지연 제로 준 말을해야에 대해서?

답변

4

당신은에 click 이벤트를 바인딩하려면 여기를 event delegation을 사용할 필요가 귀하의 동적 divspan 요소 #pejiGrid 내부 생성 : 이제

$('#pejiGrid').on('click', 'span.close', function() { 
    $(this).closest('div.modal').fadeOut(0); 
}); 
+0

+1 난 당신이 재미있는 점은 ... upvoting 해요, 그것은의를 똑같은 문제! 좋은 대답. –

+0

고마워 .. 내 호버 스크립트에 관한 내 문제에 대해 저를 도울 수 있습니까? – user3304614

관련 문제