我正在使用以下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" ) );
});
});
答案 0 :(得分:3)
如果动态创建对象,则需要使用类似.delegate():
的内容http://api.jquery.com/delegate/
或者更好的是,新的.on方法:
然后绑定事件,它应该工作。例如:
$('div.thumbnail-item').on('mouseenter',function(e){ ...