如何在按钮单击时从文本框和下拉列表中复制数据

如何在按钮单击时从文本框和下拉列表中复制数据

本文介绍了如何在按钮单击时从文本框和下拉列表中复制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在开发一个包含大量文本框和下拉列表的添加条目页。

按钮点击事件,我想要复制文本框和下拉列表中的所有数据,以便下次用户想要添加相同的数据时,可以单击粘贴按钮,这样复制的所有数据都会按原样粘贴。

是吗可以写这个代码?????

Hi,

I am developing a add entry page which contains lot of textboxes and dropdownlists.
On button click event, I want to copy all the data from textboxes and dropdowns so that next time the user wants to add same data he can click on paste button so all the data which is copied is pasted as it is.
Is it possible to write code on this?????

推荐答案

<html><head><script language="JavaScript">

function ClipBoard()
{
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
}

</script>
</head>
<body>

<span id="copytext" style="height:150;width:162;background-color:pink">
This text will be copied onto the clipboard when you click the button below. Try it!
</span>

<textarea id="holdtext" style="display:none;">
</textarea>
<button onclick="ClipBoard();">Copy to Clipboard</button>

</body>
</html>





上面的代码会将跨度的值复制到剪贴板。



但正如您所提到的。您必须复制所有控件的文本,您可以遍历所有输入控件,找到每个控件的值/文本,将其存储在某些控件中字典格式,例如< controlid,value> 。然后在元素焦点上,您可以从字典中找到特定控件的值,将文本设置为剪贴板文本,当用户按下粘贴时,之前的数据将粘贴在输入字段中



希望有所帮助。



[快乐编码]



The above code will copy the value of a span to clipboard .

But as you have mentioned .You have to copy the text of all the controls, you can iterate through all the input controls , find the value / text of each control , store it in some dictionary format , like <controlid,value> . Then on focus of element you can find the value of a specific control from the dictionary , set the text as clipboard text , and when user will press paste , the previous data will be pasted in the input field

Hope that helps.

[ Happy Coding ]


这篇关于如何在按钮单击时从文本框和下拉列表中复制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:35