前沿拓展:
每個方法學(xué)習(xí)都是這樣的,知道它的使用規(guī)則不難,讓它在應(yīng)用場景中完美應(yīng)用可能是需要我們動腦子的地方。本文如有誤,歡迎留言。
拓展知識:
**到剪貼板
有時需要實現(xiàn)將內(nèi)容**到剪貼板的功能,該方法實現(xiàn)了安卓與ios的兼容
function copy(data){
var weixin = data;
var tmpInput = document.createElement('input');
tempInput.value = weixin;
document.body.appendChild(tempInput );
if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
window.getSelection().removeAllRanges();
var range = document.createRange();
range.selectNode(tempInput);//選中需要**的節(jié)點
window.getSelection().addRange(range);
var successful = document.execCommand('copy');
window.getSelection().removeAllRanges();
}else{
tempInput.select(); // 選擇對象
document.execCommand("Copy"); // 執(zhí)行瀏覽器**命令
tempInput.className = 'tempInput ';
tempInput.style.display='none';
document.body.removeChild(tempInput );//移除
layui.use('layer',function(){
const layer = layui.layer;
layer.msg('**成功')
})
}
})
原創(chuàng)文章,作者:九賢生活小編,如若轉(zhuǎn)載,請注明出處:http://xiesong.cn/5112.html