如何将变量传递给 html 元素中的 onclick 方法
How to pass a variable into the onclick method in a html element
我目前正在使用 tabulator library 根据 json 数据创建 table。
我正在尝试使用自定义单元格格式化程序将按钮添加到单元格中。
这是我的方法:
var graphButton = function(cell, formatterParams, onRendered){
var button = '<button onclick="customMethod(cell.getRow().getData())">myLabel</button>';
return button;
};
然后我将 graphButton
传递到 table 的定义中。
按钮显示正确。但是,当我单击该按钮时,我收到一条错误消息:can't find variable: cell
.
如何正确地将单元格变量传递给 customMethod
?
尝试使用这种方式不确定,但根据标准,这将是可行的
var graphButton = function(cell, formatterParams, onRendered) {
var button = `<button onclick="customMethod('${cell.getRow().getData()}')">myLabel</button>`;
return button;
};
我目前正在使用 tabulator library 根据 json 数据创建 table。 我正在尝试使用自定义单元格格式化程序将按钮添加到单元格中。
这是我的方法:
var graphButton = function(cell, formatterParams, onRendered){
var button = '<button onclick="customMethod(cell.getRow().getData())">myLabel</button>';
return button;
};
然后我将 graphButton
传递到 table 的定义中。
按钮显示正确。但是,当我单击该按钮时,我收到一条错误消息:can't find variable: cell
.
如何正确地将单元格变量传递给 customMethod
?
尝试使用这种方式不确定,但根据标准,这将是可行的
var graphButton = function(cell, formatterParams, onRendered) {
var button = `<button onclick="customMethod('${cell.getRow().getData()}')">myLabel</button>`;
return button;
};