本帖最后由 belatu 于 2011-09-30 20:31:25 编辑

解决方案 »

  1.   


    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.6/jquery.min.js"></script> 
    <script type="text/javascript" src="http://bowser.effectgames.com/~jhuckaby/zeroclipboard/ZeroClipboard.js"></script>
    <script language="JavaScript"> 
            var clip = null;
                    
            function init() {
                // setup single ZeroClipboard object for all our elements
                clip = new ZeroClipboard.Client();
                clip.setHandCursor( true );
                
                // assign a common mouseover function for all elements using jQuery
                $('.copy').mouseover( function() {
                    // set the clip text to our innerHTML
                    clip.setText( this.innerHTML );
                    
                    // reposition the movie over our element
                    // or create it if this is the first time
                    if (clip.div) {
                        clip.receiveEvent('mouseout', null);
                        clip.reposition(this);
                    }
                    else clip.glue(this);
                    
                    // gotta force these events due to the Flash movie
                    // moving all around.  This insures the CSS effects
                    // are properly updated.
                    clip.receiveEvent('mouseover', null);
                } );
                clip.addEventListener( 'onComplete', my_complete ); 
                function my_complete( client, text ) {
                 alert("已复制!" + $(client.domElement).siblings(".al").html());
                }
            }
        </script>
    </head>
    <body  onLoad="init()">
    <table>
    <tr>
       <td id="d1" >
          <span class="copy">copy text id1</span>
          <span class="al">AAA</span>
       </td>
       <td id="d2" >
          <span class="copy">copy text id2</span>
          <span class="al">BBB</span>
       </td>
    </tr>
    </table>
    </body>
    </html>
      

  2.   

    clip.setText(  $(this).siblings().first().text() );
    {alert("已复制!" + client.clipText)}