通过单击按钮从文本框复制内容。 [英] copy content from textbox by click button.

查看:73
本文介绍了通过单击按钮从文本框复制内容。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我有一个文本框,我有一些内容,当我点击按钮点击然后它复制的内容文本框本身,它不应该是你必须运行鼠标来复制它。当你点击自己复制它的按钮时,它必须是这样的。



i在这里尝试:



Hello

it is such that I have a textbox where I have some content in, and when I click the button clicks then it copies the content that is in textbox by itself, it should not be such that you have to run your mouse over to copy it. it just has to be like that when you click on the button that copies the it themselves.

i have try its here:

<asp:TextBox ID="TextBoxHenvis" CssClass="form-control input-lg" runat="server" ReadOnly="true"></asp:TextBox><br />
                <asp:Button ID="ButtonKopier" runat="server" Text="Kopier Link" OnClientClick="CopyToClipboard()" CssClass="btn btn-success" />







function CopyToClipboard() 
        { 
            var controlValue  = document.getElementById('<%=TextBoxHenvis.ClientID%>').value;
            alert(controlValue);
        }





这意味着它应该下载内容,所以当你点击ctrl + v然后抛出内容你点击了按钮。



This means in other words that it should download content and so when you click ctrl + v then throw the content into which you got by click button.

推荐答案

请看这篇文章:https://www.lucidchart.com/techblog/2014/12/02/definitive-guide-copying-pasting-javascript [ ^ ]。br />


参见: http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript [ ^ ]。



注意ere是一个非常有趣的技巧,在上面提到的答案中描述。



也就是说,浏览器使用剪贴板非常困难,因为自动复制没有用户同意它非常危险;用户不知道这一点,并且可能会丢失先前放入剪贴板的一些数据。 所以,最好不要这样做。



这是我的建议:查找任何CodeProject代码示例,比如说,你自己的代码在这个页面上的样本。请单击复制代码。你明白了吗?

所以,我建议这样做:使用CodeProject方式:这是最简单,同时也是最安全的解决方案。


-SA
Please see this article: https://www.lucidchart.com/techblog/2014/12/02/definitive-guide-copying-pasting-javascript[^].

See also: http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript[^].

Note there is a pretty interesting trick described in the answer referenced above.

That said, browser make using clipboard pretty difficult, because automatic copy without the user consent it pretty dangerous; the user is unaware of that and can loose some data previously put to the clipboard. So, better don't do it at all.

Here is my advice: find any CodeProject code sample, say, your own code sample on this very page. Please click on "Copy Code". Are you getting the idea?
So, this is what I advise: use the CodeProject way: this is the simplest and at the same time the safest solution.

—SA


是的,谢尔盖说,你应该告诉用户你正在复制到剪贴板而点击按钮或其他东西。





否则用户将丢失现有的剪贴板数据。因此,更改按钮名称,如复制到剪贴板或复制前警告。
Yes as Sergey says, you should tell the User that you are copying to clipboard while clicking the button or something.


Otherwise User would loose the existing clipboard data. So, change the button name like "copy to clipboard" or warn before copying.


这篇关于通过单击按钮从文本框复制内容。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆