大家好,我想在按钮单击上复制输入值,但是没有任何作用。请帮忙!!
<script>
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
</script>
<input type="text" class="form-control" name="myvalue" id="myvalue" value="YEAH" readonly />
<button class="btn btn-primary btn-block" onclick="copyToClipboard('#myvalue')">Copy myvalue</button>
最佳答案
function copyToClipboard() {
var textBox = document.getElementById("myvalue");
textBox.select();
document.execCommand("copy");
}
<input type="text" class="form-control" name="myvalue" id="myvalue" value="YEAH" readonly />
<button class="btn btn-primary btn-block" onclick="copyToClipboard()">Copy myvalue</button>
关于javascript - JavaScript复制输入值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47633055/