Javascript 复制到剪贴板不起作用

Javascript 复制到剪贴板不起作用,javascript,zeroclipboard,Javascript,Zeroclipboard,我正在尝试使用Zeroclipboard进行复制,我要复制多个目标 我使用的代码是 <script type="text/javascript" src="//css.freekishopping.in/freekishopping/wp-content/themes/freekishopping/assets/js/ZeroClipboard.js"></script> <style>.clip_button{background:#063;padding:

我正在尝试使用Zeroclipboard进行复制,我要复制多个目标 我使用的代码是

<script type="text/javascript" src="//css.freekishopping.in/freekishopping/wp-content/themes/freekishopping/assets/js/ZeroClipboard.js"></script>
<style>.clip_button{background:#063;padding:4px;width:100px;}</style>
<script language="JavaScript">
////copy to clip
    var clip = null;

   function $(id) { return document.getElementById(id); }

   function init() 
   {
      clip = new ZeroClipboard.Client();
      clip.setHandCursor( true );
   }

   function move_swf(ee)
   {    

      copything = document.getElementById(ee.id+"_code").value;
      clip.setText(copything);

         if (clip.div)
         {    
            clip.receiveEvent('mouseout', null);
            clip.reposition(ee.id);
         }
         else{ clip.glue(ee.id);   }

         clip.receiveEvent('mouseover', null);
var url=document.getElementbyId(ee.id+"_url").value;
    window.open(url,"_BLANK");
document.getElementbyId(ee.id).innerHTML=copything;

   }    

</script>
</head>
<input type="hidden" id="123_url" value="http://google.com">
<input type="hidden" id="123_code" value="ABCD">
<div id='123' onMouseOver='move_swf(this)' class='clip_button'>COPY</div>

.clip_按钮{背景:#063;填充:4px;宽度:100px;}
////复制到剪辑
var clip=null;
函数$(id){return document.getElementById(id);}
函数init()
{
clip=新的ZeroClipboard.Client();
clip.setHandCursor(true);
}
功能移动\u swf(ee)
{    
copything=document.getElementById(ee.id+“_code”).value;
clip.setText(copything);
如果(剪辑分割)
{    
clip.receiveEvent('mouseout',null);
重新定位(ee.id);
}
else{clip.glue(ee.id);}
clip.receiveEvent('mouseover',null);
var url=document.getElementbyId(ee.id+“_url”).value;
打开(url为“空白”);
document.getElementbyId(ee.id).innerHTML=copything;
}    
复制
此代码的教程运行良好,但我的修改代码不起作用。 我只是在点击按钮并在按钮中显示优惠券代码后,对打开alink做了一些修改 此代码托管在/test.html中的freekishopping(dot)中
任何人都可以检查我哪里做错了。

我已经打开了你的页面,这是来自错误控制台的错误

TypeError: null is not an object (evaluating 'clip.setText')               test.html:20
因此,我打开页面,似乎您的剪辑字段尚未初始化。您应该首先尝试调用init()函数


代码中的这部分是这样的

function move_swf(ee)
{
  copything = document.getElementById(ee.id+"_code").value;
  clip.setText(copything);
试着把它换成这样

function move_swf(ee)
{
  init();
  copything = document.getElementById(ee.id+"_code").value;
  clip.setText(copything);

我没有在控制台中得到null的'cannotreadproperty'setText'。你知道如何解决这个问题吗?技术上是一样的。错误表明对象(此处为
clip
)尚未初始化。错误本身是不同的,因为您可能使用我使用的不同浏览器(我的浏览器是safari)。要解决这个问题,最简单的方法当然是,在调用
setText
方法之前先调用
init()
函数。我已经改变了位置。你能检查代码并告诉我怎么做吗?复制工作正在进行,但url没有打开你的函数调用是错误的。它是
getElementById
而不是
getElementById
。还有一点建议,试着先检查一下网络控制台。当你尝试开发网站时,它是你的伙伴;)