我有一个表,当我单击row时,它会将一些内容加载到另一个表中。
问题是,当我第一次点击row时,它只加载了一次(消息“Some”和消息“Some”显示了一次)。当我单击另一行时,它加载两次(消息显示两次)。第三次,当我点击行时,它加载了三次,依此类推。
下面是我的代码:
$("#myTable tr").click(function(e){
$.ajax({
url:'<?php echo $full_path_ajax_php; ?>',
data:{'what':'2','mypath':'12345678'},
dataType:'json',
type: 'GET',
beforeSend:function(){alert('Some msg')},
success: function(){alert('Some other msg')}
});
return false;
});发布于 2010-05-19 13:14:27
您需要在父表中使用.live()函数,但不要在要使用的部分中使用此代码:
$("#myTable tr").live('click', function(e){
$.ajax({
url:'<?php echo $full_path_ajax_php; ?>',
data:{'what':'2','mypath':'12345678'},
dataType:'json',
type: 'GET',
beforeSend:function(){alert('Some msg')},
success: function(){alert('Some other msg')}
});
return false;
});记住,只在父页面或表中出现一次。
发布于 2010-05-19 13:10:09
尝试使用id而不是'tr',您将在函数的单击事件中获得id。我想这可能行得通,如果我错了,请纠正我。
https://stackoverflow.com/questions/2862865
复制相似问题