0

我正在使用以下 jquery 代码来提示图像和触发 ajax 调用请求。直到某一点工作正常,但是在通过 ajax 重新加载 div 之后,工具提示和滑块实际上应该能够启动新的 ajax 调用的东西正在停止工作。

// 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" ) );
});

});
4

1 回答 1

3

如果一个对象是动态创建的,你需要使用 .delegate() 之类的东西:

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

或者,更好的是,更新的 .on 方法:

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

然后绑定事件,它应该可以工作。例如:

 $('div.thumbnail-item').on('mouseenter',function(e){ ...
于 2012-05-27T17:57:31.340 回答