kri*_* kr 5 html javascript jquery clipboarddata
我正在尝试通过使用以下代码来执行复制到剪贴板的操作,并且该代码在台式机浏览器中可以正常工作,但是当涉及到移动浏览器(如IOS野生动物园/ 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();
});
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个完美的解决方案,但现在不是附加到,而是附加body到正在点击的元素。这会导致滚动很小,而不是一直滚动到页面底部。在 jQuery 中,我使用:
$(this).append($temp);
Run Code Online (Sandbox Code Playgroud)