我正在尝试使用angularjs应用程序中的伪输入元素将字符串复制到剪贴板中。调用以下广播处理程序,并将input.value设置为正确的值。但是window.deocument.execCommand((无效。
$scope.$root.$on('on-share-link-made', function (event, args) {
var input = $('#MyInput')[0];
input.value = args.uri;
input.select();
window.document.execCommand("copy");
});
我需要查看你的html,可能还有css。如果输入具有display: none
、width: 0
或height: 0
,则execCommand
不起作用。如果您试图在ui中复制一些字符串,最好的方法是使用视觉之外的绝对/固定位置来定位输入标记。
window.document.execCommand只有在事件处理程序(如按钮单击(中调用时才能工作。