我正在使用zeroclipboard将文本复制到剪贴板,但是第二次单击按钮后文本被复制了吗? [英] I am using zeroclipboard for copying text to clipboard but the text gets copied after I click the button second time?Plz help

查看:92
本文介绍了我正在使用zeroclipboard将文本复制到剪贴板,但是第二次单击按钮后文本被复制了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function test() {

        ZeroClipboard.setMoviePath('zeroclipboard/ZeroClipboard.swf');
           //create client
           var clip = new ZeroClipboard.Client();

           //event
           clip.addEventListener('mousedown', function () {
               clip.setText(document.getElementById('box-content').value);

           });
         clip.addEventListener('complete', function (client,text) {
               alert('copied: ' + text);

           });
           //glue it to the button
           clip.glue('copy');

       }





My aspx code


<<blockquote class="FQ"><div class="FQA">Quote:</div>body>
    <form id="form1" runat="server">
    <div>
    <textarea name="box-content" id="box-content" rows="5" cols="70">
  This is a test text 
</textarea>
<br /><br />
<p><input type="button" id="copy" name="copy" value="Copy to Clipboard" onclick="javascript:test();" /></p>

<p>
<%--<asp:Button ID="copy" runat="server" Text="Copy to Clipboard" OnClientClick="javascript:test();" />--%>
</p>
    </div>
    </form>
</body</blockquote>>

推荐答案

您已经在单击按钮时调用了功能测试.此处将进行ZeroClipboard的初始化,这就是为什么需要第二次单击才能在加载时激活更好的初始化ZeroClipboard的原因

You have invoked function test on button click. There the initialization of the ZeroClipboard will take place thats why it require second click to activate better initialize ZeroClipboard at on load

window.onload = function MyFunction() {
                var sss = "my Name";
                var clip = clip = new ZeroClipboard.Client();
                clip.setText(sss);
                clip.glue('d_clip_button');
            }



或使用



or use

var clip = clip = new ZeroClipboard.Client();
            window.onload = function MyFunction() {
                var sss = "my Name";                
                clip.setText(sss);
                clip.glue('d_clip_button');
            }

            clip.addEventListener('onMouseDown', function (client) {
                 //alert("mouse over");
            });


这篇关于我正在使用zeroclipboard将文本复制到剪贴板,但是第二次单击按钮后文本被复制了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆