When we make the mobile Web page, we often encounter such a problem, how to click on a "Copy" button, a string of text copied to the phone clipboard, as shown in.
Look at some of the methods on the net, feel those methods are too complex, a bit to use plug-ins, and some need to install flash, but these for mobile devices such as mobile phones are not suitable, then there is a simple point of the way?
Today, let's introduce a simple and practical good way:
① First, we make the part that needs to be copied into a readonly input,
② Copy the ID of the button I set here: Js-copy-text,
③js as follows:
<script> $ ("#js-copy-text"). Click (function () { var text = $ ( this). Prev (); //is the input to be copied Text.select (); Document.execcommand (false); }); </script>
This way, when we click the Copy button, we can copy the required text down ~ ~ ~
Copy or reference Please specify the source Oh ~ ~
JS Click the Copy button to copy the text to the phone clipboard