search

Home  >  Q&A  >  body text

How to make the text in the web page selected by default? The kind that can be copied directly by right-clicking.

How to make the text in the web page selected by default? The kind that can be copied directly by right-clicking.

Please ask the master for advice. . . . . . . . . . .

P粉726632954P粉726632954920 days ago1287

reply all(3)I'll reply

  • 大瓶可乐@php.cn

    大瓶可乐@php.cn2022-06-30 01:36:59

    Try this code

    <div class="nhtMsgText">

    <input type="text" value="MSC10" readonly class ="msg_cord">

    <input type="button" value="Copy">

    </div>

    $(".nhtMsgText input[type='button']").click(

    function () {

    $('input.msg_cord').focus(); //Select Object

    $('input.msg_cord').select(); //Select object

    document.execCommand("Copy"); //Execute browser copy command

    })

    reply
    0
  • autoload

    autoload2022-06-29 09:26:55

    Do you want to implement this function on your website? Directly add a button click event and use document.execCommand

    reply
    0
  • P粉726632954

    Is there any code for reference?

    P粉726632954 · 2022-06-29 15:10:00
  • Cancelreply