How to make the text in the web page selected by default? The kind that can be copied directly by right-clicking.
P粉726632954
P粉726632954 2022-06-28 15:07:45
0
3
1253

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粉726632954
P粉726632954

reply all(2)
大瓶可乐

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

})

autoload

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

  • reply Is there any code for reference?
    P粉726632954 author 2022-06-29 15:10:00
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template