javascript 单击按钮时在 jquery/java 脚本中粘贴函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16623797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 05:23:22  来源:igfitidea点击:

Paste function in jquery/java script on button click

javascriptjquery

提问by amit ghosh

I have a textbox for write website url.And I place a button beside that.

我有一个用于编写网站 url 的文本框。我在旁边放了一个按钮。

I want if a user copy a url from any place and click on that button then the copied url paste in that textbox.

我想如果用户从任何地方复制 url 并单击该按钮,然后将复制的 url 粘贴到该文本框中。

Now I can use ctrl+v to paste the url in the text box.But then mobile user not able to use that. So I need on click on that button the copied url paste in textbox.

现在我可以使用 ctrl+v 将 url 粘贴到文本框中。但是移动用户无法使用它。所以我需要点击那个按钮,将复制的 url 粘贴到文本框中。

Any help highly appreciable and thanks in advance.

任何帮助都非常值得赞赏,并提前致谢。

回答by Mark Amery

Based upon many SO questions from the past...

基于过去的许多 SO 问题......

... the answer is probably "No, it's impossible."

……答案大概是“不,不可能。”

I would suggest, though, that you've skipped an important step in your development process. The problem you face is that you want to allow mobile users to painlessly enter text (in particular, URLs, which are a pain to type) from other sources into a textbox on your site. Take a step back and look at other possible solutions to that problem that don't involve Javascript access to the user's clipboard.

不过,我建议您跳过开发过程中的一个重要步骤。您面临的问题是,您希望允许移动用户轻松地将来自其他来源的文本(特别是 URL,键入起来很麻烦)输入到您网站上的文本框中。退后一步,看看该问题的其他可能解决方案,这些解决方案不涉及对用户剪贴板的 Javascript 访问。

In fact, the 'solution' you're currently trying to implement doesn't even help the user, because the 'click to paste' button is only helpful to a mobile user if they've already succeeded in copying something to their clipboard, and if they've managed that, then presumably they already know how the native Copy/Paste functionality of their phone browser works, so they don't need your button. There are two necessary steps in the user flow you've described: copying a URL from some other source, and pasting it on your site. Even if what you're currently asking for were possible, it could only possibly help you make the secondstep easier for the user.

事实上,您当前尝试实施的“解决方案”甚至对用户没有帮助,因为“单击粘贴”按钮仅对移动用户已经成功将某些内容复制到剪贴板时才有帮助,如果他们已经做到了,那么大概他们已经知道他们手机浏览器的本地复制/粘贴功能是如何工作的,所以他们不需要你的按钮。您描述的用户流程中有两个必要步骤:从其他来源复制 URL,并将其粘贴到您的网站上。即使你当前要求是可能的,它只能有可能帮助您做出第二步用户更容易。

Instead, I figure you should check how copy and paste work on different available brands of smart phones and their browsers. If any of them use obscure or opaque interfaces that you worry your users may be unfamiliar with, have a button near your text box that is shown only to users of those platforms that gives them platform-targeted instructions on how to use their native copy and paste functionality.

相反,我认为您应该检查复制和粘贴在不同品牌的智能手机及其浏览器上的工作方式。如果其中任何一个使用您担心您的用户可能不熟悉的晦涩或不透明的界面,请在您的文本框附近放置一个按钮,该按钮仅向那些平台的用户显示,为他们提供有关如何使用其本机副本的针对平台的说明和粘贴功能。