关闭不在ZeroClipboard中工作

我有ZeroClipBoard的以下JS代码:

onComplete: function(item) { var text= $(item).html();//Not working when I hover the clip //var text= 'Hello';// This is working when I hover the clip var clip = new ZeroClipboard.Client(); clip.setHandCursor(true); clip.addEventListener('complete', function(client, text) { debugstr("Copied text to clipboard: " + text ); }); clip.addEventListener('mouseOver', function(client) { clip.setText(text); }) // glue specifying our button AND its container clip.glue('id_clip_button', 'id_clip_container'); }, 

上面的oncomplete是一个函数,它被称为某个动作。 我从它得到的项目是html元素。 现在在上面的代码中:

  var text= $(item).html();//Not working when I hover the clip //var text= 'Hello';// This is working when I hover the clip 

如果我注释第一行并取消注释第二行,则剪辑正在工作,文本将被复制到剪贴板。 但是我必须在复制文本时使用该html元素的值。 那我该怎么做呢? 我现在正在获得控制的价值

var text = $(item).html(); //

但是当调用hoverfunction时它会丢失。 我以为它将通过Closure保留。 我错过了什么吗? 我无法在此行获取文本的值:

 clip.setText(text); 

当我在clip.addEventListener(’mouseOver’,’function(client){clip.setText(text);}中时,我无法从外部访问任何变量

函数调用中不会保留该值,您需要使用$.proxy

  clip.addEventListener('mouseOver', $.proxy(function(client) { // "this" is now set to text clip.setText(this); }, text));