使用Tab键导航时会触发Click事件

时间:2020-01-22 09:59:48

标签: javascript jquery html google-chrome-extension

我对按钮上的单击绑定有一个小问题,当我使用TAB键浏览某些字段时会触发该按钮。

我正在开发Chrome扩展程序,所以我正在处理一个已经创建的页面。我有一个table,它完全由一些页面内部的Javascript代码管理。 在扩展程序中,我必须在此表的每一行上添加一个按钮。当用户单击此按钮时,它必须检索相关行的列并将其粘贴到文本框中。

在这些表行中,您可以按键盘上的 TAB 键逐列进行。我只是注意到,当我按 TAB 键和导航列时,会随机触发列的复制粘贴(绑定到按钮的click事件)。 ENTER ,我在其中选择字段。

$('.addActivity').click(function(e) {
  let row = $(this).closest('tr');
  let string = $(row).find('td[id*="s_3_l_Created"]').text() + ' - ' + $(row).find('td[id*="s_3_l_Primary_Owned_By"]').html() + ' - ' + ($(row).find('td[id*="s_3_l_Type"]').find('a').length ? $(row).find('td[id*="s_3_l_Type"]').find('a').html() : $(row).find('td[id*="s_3_l_Type"]').find('input').val()) + ' - ' + ($(row).find('td[id*="s_3_l_Description"] textarea').length ? $(row).find('td[id*="s_3_l_Description"] textarea').val() : $(row).find('td[id*="s_3_l_Description"]').find('div').html());
  console.log('ADDED ACTIVITY ON CLICK');

  $('#sh_status').val(string + '\n' + $('#sh_status').val().trim());
  if (settings.activityTracker.autoSave) 
    _forceSiebelUpdate();
  else 
    _toSave();

  console.log(e.which);

  e.preventDefault();
  e.stopPropagation();
  return false;
});

.addActivity类是按钮。您知道为什么会这样触发吗?

0 个答案:

没有答案
相关问题