js跨浏览器复制: ZeroClipboard

实例结构:

js跨浏览器复制: ZeroClipboard

demo.html

<script type="text/javascript" src='http://code.jquery.com/jquery.js'></script>
<script type="text/javascript" src="ZeroClipboard.js"></script>
<script>
$(function(){

    //选中代码
    $('.txt_code').click(function(){
        $(this).select();
    });

    //设置swf路径
    ZeroClipboard.setMoviePath("ZeroClipboard.swf");
    //创建对象
    var clip = new ZeroClipboard.Client();
    //设置手型
    clip.setHandCursor(true);
    //绑定按钮
    clip.glue('btn_copy');
    //复制内容
    clip.addEventListener( "mouseOver", function(client) {
        client.setText($('.txt_code').val());
    });
    //复制成功后的提示
    clip.addEventListener( "complete", function(){
        alert("copyed successful");
    }); 

});

</script>

<textarea class='txt_code'>sssssssssss</textarea>
<input type='button' value='copy' id='btn_copy' />

  

;

上一篇:Leetcode 5. Longest Palindromic Substring(最长回文子串, Manacher算法)


下一篇:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)