【问题标题】:zclip is not working when i bind that on a hidden element当我将它绑定在隐藏元素上时,zclip 不起作用
【发布时间】:2014-09-17 14:15:41
【问题描述】:

我想在我的网站上有一个复制按钮,它将 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() {}
});

提前致谢!

【问题讨论】:

  • 如果它不能与隐藏字段一起使用,则使用.show() 显示它,然后在其上初始化zclip
  • 我也试过了,但对我不起作用。感谢您抽出宝贵的时间

标签: jquery zclip


【解决方案1】:

我已经找到了解决方案,我尝试将事件绑定到 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() {}
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    • 2014-01-04
    相关资源
    最近更新 更多