Javascript 按引导表isn'单击单元格;行不通

Javascript 按引导表isn'单击单元格;行不通,javascript,html,jquery,bootstrap-4,html-table,Javascript,Html,Jquery,Bootstrap 4,Html Table,我将编写一个方法,从单击的引导表中给出单元格值。当我首先单击表标题时,调用了th函数。之后,我不能点击单元格。tdOnClick()方法仅在我单击该按钮之前有效。为什么会这样 我的JS: //if a cell was clicked, this function was called function tdOnClick(){ var col = $(this)[0].textContent; console.log(col); } 必须在创建表体的函数之后添加tdOnCl

我将编写一个方法,从单击的引导表中给出单元格值。当我首先单击表标题时,调用了th函数。之后,我不能点击单元格。tdOnClick()方法仅在我单击该按钮之前有效。为什么会这样

我的JS:


//if a cell was clicked, this function was called
function tdOnClick(){
    var col = $(this)[0].textContent;
    console.log(col);
}

必须在创建表体的函数之后添加tdOnClick()函数