2012-05-27 3 views
0

У меня есть следующий код jquery, который я использую для всплывающих подсказок и запуска вызовов ajax-вызовов. До тех пор, пока точка не работает нормально, но после того, как div перезагружается ajax, всплывающая подсказка и слайдер, на самом деле должен иметь возможность запустить новый вызов ajax, перестают работать.jquery не будет refire после ajax reload

// Load this script once the document is ready 
$(document).ready(function() { 

// Get all the thumbnail 
$('div.thumbnail-item').mouseenter(function(e) { 

    // Calculate the position of the image tooltip 
    x = e.pageX - $(this).offset().left; 
    y = e.pageY - $(this).offset().top; 

    // Set the z-index of the current item, 
    // make sure it's greater than the rest of thumbnail items 
    // Set the position and display the image tooltip 
    $(this).css('z-index','15') 
    .children("div.tooltip") 
    .css({'top': y + 10,'left': x + 20,'display':'block'}); 

}).mousemove(function(e) { 

    // Calculate the position of the image tooltip 
    x = e.pageX - $(this).offset().left; 
    y = e.pageY - $(this).offset().top; 

    // This line causes the tooltip will follow the mouse pointer 
    $(this).children("div.tooltip").css({'top': y + 10,'left': x + 20}); 

}).mouseleave(function() { 

    // Reset the z-index and hide the image tooltip 
    $(this).css('z-index','1') 
    .children("div.tooltip") 
    .animate({"opacity": "hide"}, "fast"); 
}); 



$(function() { 
    $(".slider").slider({ 
     value:0, 
     min: 0, 
     max: 100, 
     step: 10, 
     change:function(e,ui){ 

      var domain = document.domain; 
      var count = $('#amount').val(); 
      var $parent = $(this).closest(".product_box"); 
      var modul_title = $("h4", $parent).text(); 
      alert(count); 
      $.ajax({ 

       url:'index/ajax', 
       data:{mod_title:modul_title, domain:domain, count:count}, 
       cache:true, 
       datatype:'html', 
       success: function(response) { 
        if(response.status = modul_title) { 
         $parent.fadeOut(); 
         $parent.html(response).fadeIn(); 

        } else 

        { 
          alert("something went wrong!"); 
        } 

        } 

       }); 

     }, 
     slide: function(event, ui) { 
      $("#amount").val(ui.value); 
     } 



    }); 
    $("#amount").val($("#slider").slider("value")); 
}); 

}); 
+0

Не забудьте локализовать переменные - 'var x = ....; var y = .....; 'иначе они будут созданы в глобальном пространстве имен и могут взаимодействовать. –

ответ

3

Если объект создается динамически вам нужно будет использовать что-то вроде .delegate():

http://api.jquery.com/delegate/

или, еще лучше, новый метод .он:

http://api.jquery.com/on/

Затем свяжите события и он должен работать. Например:

$('div.thumbnail-item').on('mouseenter',function(e){ ... 
+0

хорошо, спасибо большое! – lgt

Смежные вопросы