当客户端点击Button时,我正在尝试使用Zero * Clipboard *将文本从TextBox复制到剪贴板.我正在尝试这个很多天,但没有运气使这项工作.
在场景中,我有一个文本框,它从数据库中呈现数据.我有一个按钮,当客户点击时应该复制文本框的文本.我试过跟随,但它不起作用.
一些帮助将不胜感激.
<script type="text/javascript" src="/Scripts/ZeroClipboard.js"></script> <script type="text/javascript"> ZeroClipboard.setMoviePath('/Scripts/ZeroClipboard.swf'); </script> <script> function test() { ZeroClipboard.setMoviePath('/Scripts/ZeroClipboard.swf'); //create client var clip = new ZeroClipboard.Client(); //event clip.addEventListener('mousedown',function () { clip.setText(document.getElementById('TextBox2').value); }); clip.addEventListener('complete',function (client,text) { alert('copied: ' + text); }); //glue it to the button clip.glue('d_clip_button'); } </script> <asp:TextBox ID="TextBox2" runat="server" BorderStyle="None" Enabled="False" Font-Size="Medium" ForeColor="Black" Width="213px"></asp:TextBox> <asp:Button ID="d_clip_button" runat="server" Text="Copy" OnClientClick="javascript:test();" />
解决方法
<html> <body> <button id="copy-button" data-clipboard-text="Copy Me!" title="Click to copy me."> Copy to Clipboard</button> <script src="ZeroClipboard.js"></script> <script src="main.js"></script> </body> </html> //In Main.js file // main.js var clip = new ZeroClipboard( document.getElementById("copy-button"),{ moviePath: "/path/to/ZeroClipboard.swf" } ); clip.on( 'load',function(client) { // alert( "movie is loaded" ); } ); clip.on( 'complete',function(client,args) { this.style.display = 'none'; // "this" is the element that was clicked alert("Copied text to clipboard: " + args.text ); } ); clip.on( 'mouSEOver',function(client) { // alert("mouse over"); } ); clip.on( 'mouSEOut',function(client) { // alert("mouse out"); } ); clip.on( 'mousedown',function(client) { // alert("mouse down"); } ); clip.on( 'mouseup',function(client) { // alert("mouse up"); } );