单击JS

时间:2017-01-19 13:35:56

标签: javascript jquery clipboard

我知道围绕这个问题有其他类似的例子。但没有人喜欢这个。

我正在尝试使用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');
});

提前致谢。

1 个答案:

答案 0 :(得分:1)

您需要选择文本到临时位置,而不是调用Private Sub btnGuardar_Click(sender As Object, e As RoutedEventArgs) Handles btnGuardar.Click validarCampos() End Sub Private Sub CaptureValue() If uc.txtCedula1 = Nothing Then MessageBox.Show("Ivalid", "SmartTruck", MessageBoxButton.OK, MessageBoxImage.Information) End If End Sub 。我有这个适合我的代码:

.execCommand('copy')
相关问题