Html 如何将复制按钮链接到表中的单元格?

Html 如何将复制按钮链接到表中的单元格?,html,button,html-table,Html,Button,Html Table,我有一个复制按钮脚本: function myFunction() { var table = document.getElementById('myTable'); var copyText = table.rows[1].cells[0].innerHTML; copyText.select(); document.execCommand("copy"); alert("Copied"); } 还有我的桌子: <table id="myTabl

我有一个复制按钮脚本:

function myFunction() {
    var table = document.getElementById('myTable');
    var copyText = table.rows[1].cells[0].innerHTML;
    copyText.select();
    document.execCommand("copy");
    alert("Copied");
}
还有我的桌子:

<table id="myTable">
{% for resp in results %}
        <tr>
            <td>{{ resp }}</td>
            <td>{{ resp.Question_id.Statement }}</td>
            <td><button onclick="myFunction()">Copy text</button></td>
        </tr>
    {% endfor %}
</table>    

{resp in results%}
{{resp}}
{{resp.Question_id.Statement}
复制文本
{%endfor%}
我希望按钮复制td{{resp}}/td中的文本

函数myFunction(val,事件){
var inp=document.createElement('input');
document.body.appendChild(inp)
inp.value=val;
inp.select();
document.execCommand('copy',false);
inp.remove();
警报(“复制”);
}

一
复制文本
二
复制文本
三
复制文本
四
复制文本

当我输入“response”这样的变量时,它就起作用了。但是,如果我要复制的变量是这种格式的{{resp}}copy text,请尝试直接传递resp.tryted myFunction(resp)和myFunction({resp}'),两者都不起作用您使用的前端是什么?我使用django作为前端