jQuery eq()切换所有元素

时间:2018-12-31 21:13:19

标签: javascript jquery removechild

我正在使用eq仅获得特定的div,当我单击“ X”时,应关闭指定的div。但是发生的是,当我单击eq 0时,它关闭了eq 1和2,当我单击eq 1的div时,它关闭了eq 2。

$('.' + tabHistoryBtn).eq(0).click(function() {
  $('.' + currentDivTabBarContent).eq(0).remove();
  $('.' + tabHistory).eq(0).remove();
});

$('.' + tabHistoryBtn).eq(1).click(function() {
  $('.' + currentDivTabBarContent).eq(1).remove();
  $('.' + tabHistory).eq(1).remove();
});

$('.' + tabHistoryBtn).eq(2).click(function() {
  $('.' + currentDivTabBarContent).eq(2).remove();
  $('.' + tabHistory).eq(2).remove();
});

0 个答案:

没有答案