2014-02-17 28 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

這裏需要使用event delegationclick事件綁定到你的動態創建divspan元素內#pejiGrid

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

+1現在我upvoting你......有趣的是,它的完全相同的問題!好答案。 –

+0

謝謝..你能幫我瞭解我的問題,這是關於我的懸停腳本? – user3304614

相關問題