
C# Language//复制:
private
void
button1_Click(
object
sender, System.EventArgs e) {
if
(textBox1.SelectedText !=
""
)
Clipboard.SetDataObject(textBox1.SelectedText);
}
//粘贴:
private
void
button2_Click(
object
sender, System.EventArgs e) {
IDataObject iData = Clipboard.GetDataObject();
if
(iData.GetDataPresent(DataFormats.Text)) {
textBox2.Text = (String)iData.GetData(DataFormats.Text);
}
}
JS language
function jsCopy() {
var e = document.getElementById("contents"); //对象是contents
e.select()(); //选择对象
document.execCommand("Copy"); //执行浏览器复制命令
}
Jquery language
function jsCopy(obj) {
var __obj = $("#" + obj).focus(); //对象是obj ,obj是字符串
__obj.select(); //选择对象
document.execCommand("Copy"); //执行浏览器复制命令
}
<asp:TextBox ID="txtPlayer" runat="server" Width="392px"></asp:TextBox><input type="button"
class="inputbutton" id="btnCopy" onclick="jsCopy('txtPlayer');" value="复制地址" />