我创建了一个执行特定功能的函数。但是我不想一遍又一遍地重复该功能,只是在我的classes
函数上更改了click
。因此,我认为,如果将所有这些classes
添加到函数中,代码看起来会更加简洁。但是问题是:如何检测我单击的元素。在这种情况下,假设我单击了.firstRowLeftTable
。如何只向我的HTML
类添加一些.first
$(".firstRowLeftTable .addFurcation, .secondRowLeftTable .addFurcation").click(function() {
$(".first>div:nth-child("+($(this).index()+1)+")").html(...); // If "firstRowLeftTable" was clicked, add some HTML only to this element
$(".second>div:nth-child("+($(this).index()+1)+")").html(...);
});
答案 0 :(得分:0)
使用点击事件属性target
#(".first>div").on("click", foo);
var foo = (e) => {
var elem = e.target;
}