这是jquery部分
<script>
function copy()
{
try
{
$('#link').select();
document.execCommand('copy');
}
catch(e)
{
alert(e);
}
}
</script>
此HTML部分
<div class="row">
<?php
//scan "uploads" folder and display them accordingly
$folder = "uploads";
$results = scandir('uploads');
foreach ($results as $result) {
if ($result === '.' or $result === '..') continue;
if (substr($result, -4) == '.jpg' or substr($result, -4) == '.png') {
echo '
<div class="col-md-3">
<div class="thumbnail">
<img src="'.$folder . '/' . $result.'" alt="...">
<div class="caption">
<p>'. $result .' </p>
<p><a href="'.$folder . '/' . $result.'" role="button">Download</a>
<a href="remove.php?name='.$result.'" role="button">Remove</a> </p>
<textarea id="link" style="display:none">'.$folder . '/' . $result.'</textarea>
<div align="center"><span class="btn-md" onclick="copy();">copy</span></div>
</div>
</div>
</div>';
}
}
?>
</div>
我想让按钮在点击时自动将文件URL复制到用户剪贴板。但是,当它在每个链接中复制并单击复制按钮时,只复制第一个? 但我想复制每个人的链接。
请通过建议我应该尝试使其发挥作用来帮助我。