猿问

ZeroClipboard.js

1.ZeroClipboard.js需要点击两次才复制成功


var footer = $('<div class="modal-footer text-right "><button type="button" class="ub-btn ub-btn-default zclip">全部复制到剪切板</button> </div>')

var client = new ZeroClipboard($('.zclip',footer));


        $('.zclip',footer).click(function(){

            alert("出行人信息复制成功,随处粘贴可用!")

            client.setText(textarea.val());


        });


有只小跳蛙
浏览 319回答 1
1回答

弑天下

1.重点:目录文件:这个底层是flash 所以保证swf文件与脚本在同级目录2.data-clipboard-target="content"设置属性3.本测试用的2.X<!DOCTYPE html><html>&nbsp; &nbsp; <head>&nbsp; &nbsp; &nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; &nbsp; &nbsp; <title></title>&nbsp; &nbsp; </head>&nbsp; &nbsp; <body>&nbsp; &nbsp; &nbsp; &nbsp; <textarea id="content" rows="10" cols="40">这里是需要复制的内容</textarea><input id="copy" type="button" data-clipboard-target="content" value="复制"><script type="text/javascript" src="js/jquery.js" ></script>&nbsp; &nbsp; &nbsp; &nbsp; <script src="js/ZeroClipboard/ZeroClipboard.min.js"></script>&nbsp; &nbsp; &nbsp; &nbsp; <script>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /**1、ZeroClipboard依赖于jquery,确保引入了jquery,并放在同一目录下。2、ZeroClipboard.js&nbsp; &nbsp;ZeroClipboard.min.js&nbsp; &nbsp;ZeroClipboard.swf三个文件放在同一目录下。3、上代码: */&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(document).ready(function() {&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var clip = new ZeroClipboard($("#copy"));&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clip.on('error', function (event) {&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert("复制失败,请手动复制。");&nbsp; .&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clip.on('aftercopy', function (event) {&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert("复制成功!");&nbsp; +&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </script>&nbsp; &nbsp; </body></html>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答