ਕਿਵੇਂ ਲਿਖਤ ਨੂੰ ਕਾਪੀਬੋਰਡ 'ਤੇ ਕਾਪੀ ਕਰਨਾ ਹੈ
ਜਾਵਾਸਕ੍ਰਿਪਟ ਦੀ ਵਰਤੋਂ ਨਾਲ ਕਾਪੀਬੋਰਡ 'ਤੇ ਲਿਖਤ ਕਾਪੀ ਕਰਨਾ ਸਿੱਖੋ
ਇਸ ਬਟਨ 'ਤੇ ਕਲਿੱਕ ਕਰਕੇ ਲਿਖਤ ਫੀਲਡ ਤੋਂ ਲਿਖਤ ਕਾਪੀ ਕਰ ਸਕਦੇ ਹੋ
ਲਿਖਤ ਕਾਪੀ ਕਰੋ ਅਤੇ ਕਾਪੀਬੋਰਡ 'ਤੇ ਪਾਓ
ਪਹਿਲਾ ਕਦਮ - ਐੱਚਟੀਐੱਮਐੱਲ ਜੋੜਨਾ:
<!-- 文本字 --> <input type="text" value="Hello World" id="myInput"> <!-- ਟੈਕਸਟ ਕਾਪੀ ਕਰਨ ਲਈ ਬਟਨ --> <button onclick="myFunction()">ਟੈਕਸਟ ਕਾਪੀ ਕਰੋ</button>
ਕਦਮ 2 - ਜਾਵਾਸਕ੍ਰਿਪਟ ਜੋੜੋ:
function myFunction() { // ਟੈਕਸਟ ਫੀਲਡ ਨੂੰ ਪ੍ਰਾਪਤ ਕਰੋ var copyText = document.getElementById("myInput"); // ਟੈਕਸਟ ਫੀਲਡ ਨੂੰ ਚੋਣਨ ਕਰੋ copyText.select(); copyText.setSelectionRange(0, 99999); // ਮੋਬਾਈਲ ਉਪਕਰਣਾਂ ਲਈ // ਟੈਕਸਟ ਫੀਲਡ ਵਿੱਚ ਟੈਕਸਟ ਕਾਪੀ ਕਰੋ navigator.clipboard.writeText(copyText.value); // ਕਾਪੀ ਕੀਤੇ ਗਏ ਟੈਕਸਟ ਨੂੰ ਨੋਟੀਫਾਈ ਕਰੋ alert("Copied the text: " + copyText.value); }
ਟੂਲਟਿਪ ਵਿੱਚ ਕਾਪੀ ਕੀਤੇ ਗਏ ਟੈਕਸਟ ਦਿਖਾਓ
ਸਕਰੀਨ ਵਿੱਚ ਸਟਾਈਲ ਜੋੜੋ:
.tooltip { position: relative; display: inline-block; } .tooltip .tooltiptext { visibility: hidden; width: 140px; background-color: #555; color: #fff; text-align: center; border-radius: 6px; padding: 5px; position: absolute; z-index: 1; bottom: 150%; left: 50%; margin-left: -75px; opacity: 0; transition: opacity 0.3s; } .tooltip .tooltiptext::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -5px; border-width: 5px; border-style: solid; border-color: #555 transparent transparent transparent; } .tooltip:hover .tooltiptext { visibility: visible; opacity: 1; }