我想在我的网站上使用一个按钮,该按钮应该将剪贴板中的数据粘贴到制表符表中。因此,用户也可以单击该按钮,而不是在表格上按 CTRL + V。我想通过将焦点设置到表格并刺激 CTRL + V 按键来实现这一点,但这不起作用......有人可以帮助我改进我的代码吗?或者也许有比刺激按键更简单的解决方案。我的代码:
$("#tabulator_table").tabulator({
data:tableData,
history:true,
clipboard:true,
clipboardPasteAction:"replace",
layout:"fitColumns",
height:"400px",
columns:[
{title:"index", editor:true},
{title:"Naam", editor:true},
{title:"number", sorter:"number"}
],
});
和
$("#paste-button").on("click", function(){
document.getElementById("tabulator_table").focus();
var e = jQuery.Event("keydown");
e.which = 86;
e.ctrlkey = true; // control key pressed
$('#tabulator_table').trigger(e);
}
});