5

我正在尝试通过使用下面的代码来复制到剪贴板操作,并且代码在桌面浏览器中运行良好,但是当涉及到 IOS safari/chrome 等移动浏览器时,页面会向下滚动$temp.val(copydatacode).select();

 $('#myelementcopy').click(function(event){         
        var copydatacode= $('.addelement').html();
        var $temp = $("<input>");
        $("body").append($temp);
        $temp.val(copydatacode).select(); // when the code execute at this line the mobile browser jumps to the page bottom                     
        document.execCommand("copy");           
        $temp.remove(); 
        return false;
        event.preventDefault();         
 });
4

1 回答 1

0

我正在寻找一个完美的解决方案,但现在不是追加到body我追加到被点击的元素上。这会导致小滚动而不是一直滚动到页面底部。在 jQuery 中,我使用了:

$(this).append($temp);
于 2019-06-23T10:01:07.823 回答