2

我有一个关于获取标题属性的问题..

$('.copy_button').livequery(function(event){
    $(this).zclip({
        path:'http://togl.me/tema/flash/ZeroClipboard.swf',
        copy: $(this).attr("title")
    });
});

livequery功能正在运行,但我无法开始attr('title')工作。

我该如何解决这个问题?

4

2 回答 2

1

有时,范围$(this)可能会根据您在方法中所处的位置而变化。随着您开始深入,$(this)可以参考当前范围内的内容,而不是首先发生的事情。

尝试这样做并告诉我它是否有效:

$('.copy_button').livequery(function(event){
    var title = $(this).attr('title');
    $(this).zclip({
        path:'http://togl.me/tema/flash/ZeroClipboard.swf',
        copy: title
    });
});
于 2011-08-26T13:29:57.577 回答
0

您可以尝试以下代码:

$('.copy_button').livequery(function(event){
    $(this).zclip({
        path:'http://togl.me/tema/flash/ZeroClipboard.swf',
        copy: this.attr("title")
    });
});
于 2011-08-26T13:34:24.300 回答