求一个点击复制的代码!!!急需~ <asp:Button ID="Button1" runat="server" Text="点击复制" onclick="Button1_Click" />点击按钮即实现对TextBox的复制,可以粘贴。 哪位大虾帮忙下,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 IE ONLYfunction SelectCopy(div_id) { if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion >= "4.0"){ for (i=0; i<document.all.length; i++) { document.all(i).unselectable = "on" } document.getElementById(div_id).unselectable = "off"; document.getElementById(div_id).focus(); document.execCommand('SelectAll'); document.execCommand('Copy'); for (i=0; i<document.all.length; i++) { document.all(i).unselectable = "off" } }else{ alert("Sorry, this only works for InternetExploder") } protected void Button1_Click(object sender, EventArgs e) { string _Script="<script type='text/javascript'> var t=document.getElementById('"+TextBox1.ID+"');t.select();window.clipboardData.setData('text',t.createTextRange().text);</script>"; ClientScript.RegisterStartupScript(this.GetType(), "CopyMem", _Script); } 不好意思,其实我是想把内容放到粘贴板上,某些网站有这些功能,这个怎么实现?并不一定要是TextBox里面的值 ,是不是你楼上的代码一样?? private void btnc_Click(object sender, System.EventArgs e) { if(TXToutput.Text!="") try { TXToutput.SelectAll(); Clipboard.SetDataObject(TXToutput.SelectedText ); MessageBox.Show("","复制成功"); } catch(Exception ex) { MessageBox.Show("Error",ex.Message ) ; } } 这个东西最好用javascript写,干嘛要交给服务器来做咧?javascript函数:function copyToClipboard(txt){ window.clipboardData.clearData(); window.clipboardData.setData("Text", txt); alert("复制成功!");}页面调用:<asp:TextBox id="TextBox1" runat="server"></asp:TextBox><input type="button" value="点击复制" onclick="copyToClipboard(document.getElementById('TextBox1').value);"/> 存储过程在查询分析运行正常,在C#中为什么就会报错?这是为什么呢?请高人来帮帮。 怎么导出数据? Console.read()问题 抢分:正则 如何让用户自助申请二级域名并绑定到用户所要求的路径? 高手们!!帮帮我解决一下这个问题把~~~~ C#中语句的意义? 解释一下这个不同F5和Ctrl+F5 500错误 单个页面合成pdf文件不出错,可是当多个页面合成pdf文件时出错 关于弹出窗口的问题,希望高手们能给点意见!先谢谢了! 关于WebRequest e.Item.Cell[0].Text
if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion >= "4.0"){
for (i=0; i<document.all.length; i++) {
document.all(i).unselectable = "on"
}
document.getElementById(div_id).unselectable = "off";
document.getElementById(div_id).focus();
document.execCommand('SelectAll');
document.execCommand('Copy');
for (i=0; i<document.all.length; i++) {
document.all(i).unselectable = "off"
}
}else{
alert("Sorry, this only works for InternetExploder")
}
{
string _Script="<script type='text/javascript'> var t=document.getElementById('"+TextBox1.ID+"');t.select();window.clipboardData.setData('text',t.createTextRange().text);</script>"; ClientScript.RegisterStartupScript(this.GetType(), "CopyMem", _Script);
}
private void btnc_Click(object sender, System.EventArgs e)
{
if(TXToutput.Text!="")
try
{
TXToutput.SelectAll();
Clipboard.SetDataObject(TXToutput.SelectedText );
MessageBox.Show("","复制成功");
}
catch(Exception ex)
{
MessageBox.Show("Error",ex.Message ) ;
}
}
javascript函数:function copyToClipboard(txt)
{
window.clipboardData.clearData();
window.clipboardData.setData("Text", txt);
alert("复制成功!");
}
页面调用:<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<input type="button" value="点击复制" onclick="copyToClipboard(document.getElementById('TextBox1').value);"/>