我有一个表。当我单击一个单元格时,它会在它下面创建显示下一级详细信息的行,使用该类的.click()事件侦听器。它通过. getjson()调用来实现这一点,然后我使用该调用来填充后面的行。我将以下.newtable
类添加到每个新的(子细节)行。在我的页面底部,我有以下内容,所以如果你点击页面上的任何地方,它会关闭这些子细节行:
$('html').click(function(){
$('.newtable').remove();
});
但是,如果用户单击其中一个新打开的单元格,我不希望它关闭子详细信息,因此我尝试了以下两种方法都无效…是b/c的行被添加后页面加载或什么?
$('.newtable td').click(function(e){
e.stopPropagation();
});
和
$(document).ready(function(){
$("table .newtable").on("click","td",function(e){
e.stopPropagation();
});
});
任何帮助都非常感谢!
我认为这应该可以为您工作,而不需要您正在尝试的其他两个代码片段。
$('html').click(function(event){
if($(event.target).hasClass('newtable') || $(event.target).parents('tr').first().hasClass('newtable')){
return;
} else {
$('.newtable').remove();
}
});