首頁  >  問答  >  主體

如何實現讓網頁中的文字預設是選取的狀態?右鍵就直接能複製的那種。

如何實現讓網頁中的文字預設是選取的狀態?右鍵就直接能複製的那種。

請教大神。 。 。 。 。 。 。 。 。 。 。

P粉726632954P粉726632954844 天前1208

全部回覆(3)我來回復

  • 大瓶可乐@php.cn

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

    試試看這個程式碼

    <div class="nhtMsgText">    

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

    <input type="button" value="複製">

    </div>    

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

    function () {    

    $('input.msg_cord').focus(); //選擇物件   

    $('input.msg_cord').select(); //選取物件   

    document.execCommand("Copy"); //執行瀏覽器複製指令   

    ###############################################################################################################################################################################################################” ##})    ###

    回覆
    0
  • autoload

    autoload2022-06-29 09:26:55

    你是要在自己網站上實現這個功能?直接新增一個按鈕 點選事件,利用document.execCommand即可

    回覆
    0
  • P粉726632954

    有沒有程式碼參考一下哈

    P粉726632954 · 2022-06-29 15:10:00
  • 取消回覆