0

ZeroClipboard 用于单击复制。两个链接都提供相同的输出,而不是不同的。演示链接在这里

<a id="c101" href="javascript:void(0);">OBJ1</a> &nbsp;&nbsp; 
<a id="x101" href="javascript:void(0);">OBJ2</a>

<script type="text/javascript">
    var dom_obj1 = document.getElementById('c101');
    var dom_obj2 = document.getElementById('x101');

    var clip1 = new ZeroClipboard();
    clip1.glue(dom_obj1);

    clip1.addEventListener( 'dataRequested', function(client, args) {
        client.setText('text1');
    });

    clip1.addEventListener( 'complete', function(client, args) {
        alert('clip1 text: '+args.text);
    });

    var clip2 = new ZeroClipboard();
    clip2.glue(dom_obj2);

    clip2.addEventListener( 'dataRequested', function(client, args) {
        client.setText('text2');
    });

    clip2.addEventListener( 'complete', function(client, args) {
        alert('clip2 text: '+args.text);
    });
</script>
4

1 回答 1

2

为所有这些元素提供一个通用类,然后将它们全部提供给 ZeroClipBoard :

<a id="c101" class=" toBeCopied " href="something"> <a
id="c102" class=" toBeCopied " href="something else">

然后像这样加载它们:

var clip = new ZeroClipboard($(" .toBeCopied "));

于 2013-09-28T15:51:00.327 回答