0

我想在我的网站上有一个复制按钮,它将 div 的文本复制到剪贴板,因为 javascript 无法直接访问剪贴板,因此我使用 zclip,但是当我将 zclip 绑定到隐藏元素时我显示该元素比 zclip 不起作用或绑定,请帮助我。

HTML 代码:

<span class="homebutton">Get code for this theme</span>
<div class="get_code">
    <pre class="theme_code"><?php echo $theme['theme_code'];?></pre>
    <div class="copy_code">Copy</div>
</div>

jQuery代码:

$('.homebutton').click(function(){
    $('.get_code').show('slow');
});

$('.copy_code').zclip({
    path: "js/ZeroClipboard.swf",
    copy: function(){return $('.theme_code').text();},
    afterCopy: function() {}
});

提前致谢!

4

1 回答 1

0

我有解决方案,我尝试将事件绑定到 setTimeout 函数上,它可以按我的需要工作.. :)

我正在分享该代码,希望对其他人有所帮助!

HTML 代码:

<span class="homebutton">Get code for this theme</span>
<div class="get_code">
    <pre class="theme_code"><?php echo $theme['theme_code'];?></pre>
    <div class="copy_code">Copy</div>
</div>

jQuery代码:

$('.homebutton').click(function(){
    $('.get_code').show('slow');
    setTimeout(function(){bind_zclip();},1000);
});

function bind_zclip()
{
    $('.copy_code').zclip({
        path: "js/ZeroClipboard.swf",
        copy: function(){return $('.theme_code').text();},
        afterCopy: function() {}
    });
}
于 2014-09-17T06:15:41.850 回答