开发者

zeroclipboard - copying and formatting text

开发者 https://www.devze.com 2023-02-07 00:14 出处:网络
I am struggling to create a selection set to pass through to a zeroclipboard client to copy the contents of the various HTML elemnts in a basically formatted form. I can pass through text to the clien

I am struggling to create a selection set to pass through to a zeroclipboard client to copy the contents of the various HTML elemnts in a basically formatted form. I can pass through text to the client directly from the variable var myTextToCopy = "Hi, this is the text to copy!"; but cannot get the text content of HTML elements to work.

Can someone point out where I am going wrong?

<script src="_assets/js/ZeroClipboard.js" type="text/javascript"></script> 
      <script language="JavaScript">
                var clip = new ZeroClipboard.Client();
    var myTextToCopy = $(".sideInfo ul:first-child").text() + "\r\n" + $(".sideInfo ul:nth-child(2)").text() + "\r\n" + $(".sideInfo ul:nth-child(3)").text() + $('.description').text();
                clip.setText( myTextToCopy );
                clip.glue( 'copyme' );
        </script>


<div id="copyme">Copy To Clipboard</div>

    <div class="sideInfo">    
      <ul>
开发者_开发百科        <li>Episode: x</li>
        <li>Production house: x</li>
        <li>Contacts: Tim nicebutdim<br><a href="mailto:nicebutdim@dot.com">nicebutdim@dot.com</a></li>
      </ul>
    </div>

  <div class="description">
Text text texttext <br /> text text text</div>


Instead of

clip.setText( txt );

use

clip.setText( myTextToCopy );

Then try to use

clip.setText($(".sideInfo").text());

Finally add this around your code

$(document).ready(function() {

// your code

)};
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号