提问人:ahmet kara 提问时间:10/10/2023 最后编辑:ahmet kara 更新时间:10/10/2023 访问量:25
复制到剪贴板在iPhone中效果不佳。Javascript的
The Copy to Clipboard doesn't work well in iPhone. Javascript
问:
我有以下代码:
<div>
<div id="copy-number"><?php echo $account_number;?></div>
<button type="button" class="btn-copy2"><i class="icon-copy icon--md"></i></button>
</div>
Javascript 部分是:
btn_copy2.addEventListener('click',()=>{
var copyText = document.getElementById("copy-number").innerHTML;
unsecuredCopyToClipboard(copyText);
});
/*COPY INSECURE TO CLIPBOARD*/
const unsecuredCopyToClipboard = (text) => {
const textArea = document.createElement("textarea");
textArea.value=text;
document.body.appendChild(textArea);
var range,selection;
if (isOS()) {
range = document.createRange();
range.selectNodeContents(textArea);
selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
textArea.setSelectionRange(0, 999999);
console.log("İOS");
}
else {textArea.select();}//Android is OK
document.execCommand('copy');
document.body.removeChild(textArea);
window.scrollTo(0, 0);/*EN alta gidiyordu..*/
};
我想将div内容复制为数字。div 仅包含数字。根据我的代码,下面的代码在 Android 和 Web 中运行良好。 它需要被复制为“1395904915” 但是iPhone像这样复制到剪贴板: ----<a .href=“tel:1395904915”>1395904915</a.>--- 您可以查看错误照片:在此处输入图像描述
答: 暂无答案
评论