【发布时间】:2011-01-30 17:54:18
【问题描述】:
我有以下用于 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 上面是 oneofmy 函数,它在某些动作上被调用。我从中得到项目,它是 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();//
但是当调用悬停函数时,它会丢失。我在想它将通过 Closure 保存。我错过了什么吗?我无法在这一行获取文本的值:
clip.setText(text);
当我在内部时,我无法从外部访问任何变量 clip.addEventListener('mouseOver', function(client) { clip.setText(text); })
【问题讨论】:
标签: javascript jquery