我有一个网站,当客户购买它们时,它会生成从https://www.sendowl.com分发的随机代码,然后在感谢页面上提供这些代码。我的问题是我想要一个复制所有代码并添加换行符的按钮。到目前为止,我得到了一次复制一个代码的东西,但我无法弄清楚这个
这是我正在使用的脚本。
<script>
function myFunction(val, event) {
var inp = document.createElement('input');
document.body.appendChild(inp)
inp.value = val;
inp.select();
document.execCommand('copy', false);
inp.remove();
alert("Copied the text: " + copyText.value);
}
</script>
这里是复制代码的按钮。{% for license in order.licenses %}{{ license.key }}{% endfor %}是必需的,因为它是生成代码的原因。
<button type="button" onclick="myFunction('{% for license in order.licenses %}{{ license.key }}{% endfor %}')"class="btn btn-primary">Copy All Codes</button>
在这方面,我是一个主要的菜鸟,所以任何帮助都将不胜感激。
代码复制如下:

我希望他们像这样复制:

这是购买后如何在页面上分发代码的屏幕截图, 感谢页面
以下是完整的感谢页面或收据
<p>Hi{% if order.receiver_name %} {{ order.receiver_first_name }}{% endif %},</p>
<p><br />Thanks for ordering from us. This email confirms your order of the following items:<br />{% for cart_item in order.cart.cart_items %}{{ cart_item.product.name }} x {{ cart_item.quantity }}<br />{% endfor %}</p>
<p>Your Order ID is {{ order.id }}{% if order.settled_gross %} and your payment has now cleared. A receipt has been emailed to you separately.{% endif %}</p>
<br>
<br>
{% assign product_types = order.cart.cart_items | map: 'product' | map: 'member_types' | flatten %}{% if product_types contains 'tangible' %}You have ordered tangible goods. These will be posted shortly and you will be notified once they have been dispatched.{% endif %}
{% if product_types contains 'digital' or product_types contains 'software' or product_types contains 'redirect' %}
{% if product_types contains 'software' %}
<button type="button" onclick="myFunction('{% for license in order.licenses %}{{ license.key }}{% endfor %}')"class="btn btn-primary">Copy All Codes</button>
<br>
<br>
<table border="1">
<tr><th> Name </th> <th> Code </th> <th> QR Code </th> <th> Copy </th>
<tr>{% for license in order.licenses %} <td>{{ license.product.name }}:</td>
<td>{{ license.key }}</td> <td> <img src="https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl={{ license.key }} " /path/to/image.jpg /> </td> <td><button type="button" onclick="myFunction('{{ license.key }}')"class="btn btn-primary">Copy Code</button> </td> </tr>
{% endfor %}{% endif %}{% endif %}
</table>
{% if product_types contains 'service' %} You have ordered service goods. The merchant will be in contact to arrange the carrying out of these services.{% endif %}
<p> </p>
<p>Thanks,</p>
<p> </p>
<p>Liquid Realms</p>
<script>
function myFunction(val, event) {
var inp = document.createElement('input');
document.body.appendChild(inp)
inp.value = val;
inp.select();
document.execCommand('copy', false);
inp.remove();
alert("Copied the text: " + copyText.value);
}
</script>