js複製文字功能實現,適用於Android和IOS

2021-10-06 13:11:47 字數 811 閱讀 6942

首先文字只有選中才可以複製,所以簡單的做法就是建立乙個隱藏的input,然後繫結需要複製的文字。

另外如果將input設定為 `type="hidden"或者display:none則無法選中文字,也就無法複製,可以設定position:absolute;left:-999px;來隱藏文字域。

const copyinput = document.queryselector('#copyinput');

copyinput.value = '需要複製的文字';

copyinput.select();

document.execcommand('copy');

let h5copylink = () =>  else );

} catch (err) );

}//刪除新增的input

document.body.removechild(inputz);

}return;

};h5copylink(con);

在 ios 中input聚焦的時候會彈起鍵盤,對於複製操作互動體驗很差,可以用以下方式禁止鍵盤的彈起。

const input = document.createelement("input");

input.readonly = 'readonly';

$("#box").focus(function());

Delphi實現強制關機(適用於各個Win系統)

unit unit1 inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,stdctrls type tform1 class tform button1 tbutton la...

js自適應rem 主要適用於移動端

rem是指相對於根元素 html 的字型大小的單位,利用它能實現強大的螢幕適配布局。下面主要應用的是基於js去調整根元素字型大小,從而實現各個尺寸螢幕的適配 使用方法 1.複製上面這段 到你的頁面的頭部的script標籤的最前面。2.根據設計稿大小,調整裡面的最後兩個引數值。3.使用1rem 100...

Redis適用於高併發的遞增 遞減功能

遞增指令 incr 預設從0開始 遞減指令 decr 預設從0開始,遞減會出現負數,這點跟memcache不一樣,mc到0 如下 附上shardedjedispool和jediscluster的兩種實現方式 shardedjedispool override public long decr str...