我创建了一个函数,做一个特定的工作。 但我不想一遍又一遍地重复那个函数,只是为了更改我的单击
函数中的类
。 所以我想,如果我把所有这些类
都添加到我的函数中,代码看起来会干净得多。 但问题是:我怎样才能检测到我点击的是哪个元素。 在本例中,假设我单击了.firstRowleftTable
。 如何只向.first
类添加一些HTML
null
$(".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(...);
});
null
使用单击事件属性target
#(".first>div").on("click", foo);
var foo = (e) => {
var elem = e.target;
}