我试图添加按钮以复制简单的文本字符串,但没有成功。
function kopiraj() {
var copyText = document.getElementById("toCopy");
copyText.select();
document.execCommand("Copy");
document.getElementById("telefon").innerHTML = 'Copied';
}
<button type="button" onclick="kopiraj()">Copy</button>
<input type="hidden" id="toCopy" value="123456789">
<p id="telefon"></p>
它不会在剪贴板中放置任何内容。
我不需要输入字段。我可以在JS本身中添加文本。
代替hidden
属性,使用屏幕外的类和aria-hidden
属性(后者用于辅助功能):
.offscreen {
position: absolute;
left: -999em;
}
<input ... class="offscreen" aria-hidden="true">
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句