[英]Two button for copy two different fields to clipboard
I have two fields with input text, there is a copy to clipboard button for each, copying works but copies the same text:我有两个带有输入文本的字段,每个字段都有一个复制到剪贴板按钮,复制作品但复制相同的文本:
<div class="class="mov-label">
<i class="mov-label"></i> <b>Link first</b>
</div>
<input type="text" value="[xfvalue_link]" id="myInput" readonly>
<div class="fb-submit flex-row-2"><button onclick="myFunction()">Copy link</button>
<form>
<input type="button" onclick="window.location.href = '[xfvalue_link]';" value="Open in application"/>
</form>
</div>
<br>
<div class="class="mov-label">
<i class="mov-label"></i> <b>Link second</b>
</div>
<input type="text" value="[xfvalue_link-2]" id="myInput" readonly>
<div class="fb-submit flex-row-2"><button onclick="myFunction()">Copy link</button>
<form>
<input type="button" onclick="window.location.href = '[xfvalue_link-2]';" value="Open in application"/>
</form>
</div>
and JS和JS
<script>
function myFunction() {
var copyText = document.getElementById("myInput");
copyText.select();
copyText.setSelectionRange(0, 99999)
document.execCommand("copy");
alert("Copied: " + copyText.value);
}
</script>
You are using same id for both the textboxes - myInput .您对两个文本框使用相同的 id - myInput 。 Assign unique id for each textbox and pass them in myFunction().为每个文本框分配唯一的 id 并将它们传递给 myFunction()。
<input type="text" value="[xfvalue_link]" id="myInput1" readonly>
<button onclick="myFunction('myInput1')">
<input type="text" value="[xfvalue_link-2]" id="myInput2" readonly>
<button onclick="myFunction('myInput2')">
function myFunction(myID){
var copyText = document.getElementById(myID);
}
This is solution:这是解决方案:
<div class="class="mov-label">
<i class="mov-label"></i> <b>Link first</b>
</div>
<input type="text" value="[xfvalue_link]" id="myInput" readonly>
<div class="fb-submit flex-row-2"><button onclick="myFunction()">Copy link</button>
<form>
<input type="button" onclick="window.location.href = '[xfvalue_link]';" value="Open in application"/>
</form>
</div>
<br>
<div class="class="mov-label">
<i class="mov-label"></i> <b>Link second</b>
</div>
<input type="text" value="[xfvalue_link-2]" id="myInput1" readonly>
<div class="fb-submit flex-row-2"><button onclick="myFunction1()">Copy link</button>
<form>
<input type="button" onclick="window.location.href = '[xfvalue_link-2]';" value="Open in application"/>
</form>
</div>
and JS和JS
<script>
function myFunction() {
var copyText = document.getElementById("myInput");
copyText.select();
copyText.setSelectionRange(0, 99999)
document.execCommand("copy");
alert("Copied: " + copyText.value);
}
</script>
<script>
function myFunction1() {
var copyText = document.getElementById("myInput1");
copyText.select();
copyText.setSelectionRange(0, 99999)
document.execCommand("copy");
alert("Copied: " + copyText.value);
}
</script>
Maybe someone will be useful也许有人会有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.