azimzadeh1398
سلام
برای اینکار لازمه از جاوااسکریپت استفاده کنید.
من براتون نمونشو با کد خودتون پیاده کردم:
<!DOCTYPE html>
<html lang=“fa”>
<head>
<meta charset=“UTF-8”>
<title>CodePen - Crack Climbing Carousel - CSS :has()</title>
</head>
<style>
body{
color:
#fff;
}
.mb {
font-family: IranSans, tahoma, Serif;
margin-bottom: 0.5rem !important;
color:
#fff;
}
.b-1 {
background-color:
#0035ff;
border-radius: 0.5rem;
padding: 7px 10px;
margin: 0 1.5rem;
float: left;
}
.mb-4 {
text-align: justify;
direction: rtl;
font-family: ‘IranSans’;
color:
#ff0000;
}
.green-tick {
display: none;
}
</style>
<body>
<p class=“b-1 mb-4”><i class=“fa me-3”></i><a class=“mb” onclick=“copyText(this)”>کپی</a></p>
<p class=“b-1 mb-4”><i class=“fa me-3”></i><a class=“mb” id=“phoneNumber”>987654321987654321</a><span class=“green-tick”>✔</span></p>
<script>
function copyText(element) {
var phoneNumber = document.getElementById(“phoneNumber”);
var range = document.createRange();
range.selectNode(phoneNumber);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand(“copy”);
window.getSelection().removeAllRanges();
element.innerHTML = “کپی شد”;
phoneNumber.nextElementSibling.style.display = “inline”;
}
</script>
</body>
</html>