Я знаю, что есть другие подобные примеры, окружающие этот вопрос. Но совсем не так.Скопируйте в буфер обмена с помощью щелчка JS
Я пытаюсь скопировать значение ввода в буфер обмена пользователя с помощью JS и jQuery с помощью execCommand
, но подозреваю, что я злоупотребляю им. Любое направление было бы высоко оценено.
Вот мой HTML:
<div class="2 columns">
<div class="js swatch container">
<div class="js swatch color chartreuse"></div>
<div class="swatch information">
<span class="swatch title">Chartreuse</span>
<input class="js swatch data" type="text" value="#31bc06" readonly>
</div>
</div>
</div>
И вот мой JS:
// .js.swatch.container
var swatchContainer = $('.js.swatch.container');
var swatchData = $('.js.swatch.data');
swatchContainer.mouseenter(function() {
$(this).children().children(swatchData).select();
});
swatchContainer.mouseleave(function() {
$(this).children().children(swatchData).blur();
});
// test
swatchContainer.click(function() {
$(this).children().children(swatchData).execCommand('copy');
});
Спасибо заранее.
ли смотрите здесь https://developers.google.com/web/updates/2015/04/cut-and-copy-commands – Stuart
Я думаю, что вам нужно ' select() 'сначала, как в http://stackoverflow.com/questions/400212/how-do-copy-to-the-clipboard-in-javascript –
Возможный дубликат [Как скопировать в буфер обмена в JavaScript ?] (http://stackoverflow.com/questions/400212/how-do-copy-to-the-clipboard-in-javascript) –