实例结构:
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' />
;