zClip不复制特定ID的文本

时间:2011-10-25 01:30:34

标签: php jquery flash zclip

我已设置链接,点击后我希望它复制文本。它会输出许多链接,所以我必须确保zClip复制正确的链接:

<a class="copy-callbacks" id="coupon-code-copy-<?php echo $couponid ; ?>" href="#"><?php echo $info['coupon'] ; ?></a>

这是我正在使用的jQuery,但它不起作用:

$(document).ready(function(){

    $("a.copy-callbacks").zclip({
        path:'scripts/ZeroClipboard.swf',
        copy: $('#' + myCopyID).text(),
        beforeCopy:function(){
            var myCopyID = $(this).attr("id");  
        },
        afterCopy:function(){
        }
    });

});

使用此代码,flash对象甚至无法加载。我不太清楚出了什么问题。我尝试过使用:

copy: $(this).text(),

flash对象加载,但由于一些奇怪的原因,它会在页脚中复制一些文本。非常感谢任何帮助!!

1 个答案:

答案 0 :(得分:0)

我从来没有使用.attr(“id”),我总是这样做。

<span class="swfTitle" style="position: relative; onmouseover="this.style.cursor='pointer'">
    Text
</span>

    $('.swfTitle').zclip({
    path: '/js/ZeroClipboard.swf',
    copy: function () {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            async: false,
            data: JSON.stringify(PageInfo),
            url: "dosomethinghere.aspx&query=string",
            timeout: 30000,
            success: function (data) {
                PageInfo = JSON.parse(data);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
            }
        });
  return PageInfo.PostHTML;
  }

其中PageInfo是js对象。总的来说,id标签与类标签不同,.swfTitle与#swfTitle不同。