JS Click the Copy button to copy the text to the phone clipboard

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.