js 剪切TextBox内容到剪切板 asp.net 中实现
<asp:TextBoxWidth="530px"Height="94px"id="TextBox1"runat="server"></asp:TextBox><inpu...
<asp:TextBox Width="530px" Height="94px" id="TextBox1" runat="server"></asp:TextBox>
<input id="Button1" class="c-btn c-btn-small" type="button" value="复制代码" onclick="oCopy()" />
利用JS代码 在点击Button1 把内容放到剪切板中! 展开
<input id="Button1" class="c-btn c-btn-small" type="button" value="复制代码" onclick="oCopy()" />
利用JS代码 在点击Button1 把内容放到剪切板中! 展开
3个回答
展开全部
function oCopy() {
txt=$("#TextBox1").val();
if(window.clipboardData)
{
window.clipboardData.clearData();
window.clipboardData.setData("Text", txt);
alert("复制成功");
}
else if(navigator.userAgent.indexOf("Opera") != -1)
{
window.location = txt;
alert("复制成功");
}
else if (window.netscape)
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e)
{
alert("!!被浏览器拒绝!\n请在浏览器地址栏输入’about:config’并回车\n然后将’signed.applets.codebase_principal_support’设置为’true’");
}
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip)
return;
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans)
return;
trans.addDataFlavor('text/unicode');
var str = new Object();
var len = new Object();
var str = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
var copytext = txt;
str.data = copytext;
trans.setTransferData('text/unicode',str,copytext.length*2);
var clipid = Components.interfaces.nsIClipboard;
if (!clip)
alert("复制失败");
clip.setData(trans,null,clipid.kGlobalClipboard);
}
alert("复制成功");
}
txt=$("#TextBox1").val();
if(window.clipboardData)
{
window.clipboardData.clearData();
window.clipboardData.setData("Text", txt);
alert("复制成功");
}
else if(navigator.userAgent.indexOf("Opera") != -1)
{
window.location = txt;
alert("复制成功");
}
else if (window.netscape)
{
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e)
{
alert("!!被浏览器拒绝!\n请在浏览器地址栏输入’about:config’并回车\n然后将’signed.applets.codebase_principal_support’设置为’true’");
}
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip)
return;
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans)
return;
trans.addDataFlavor('text/unicode');
var str = new Object();
var len = new Object();
var str = Components.classes['@mozilla.org/supports-string;1'].createInstance(Components.interfaces.nsISupportsString);
var copytext = txt;
str.data = copytext;
trans.setTransferData('text/unicode',str,copytext.length*2);
var clipid = Components.interfaces.nsIClipboard;
if (!clip)
alert("复制失败");
clip.setData(trans,null,clipid.kGlobalClipboard);
}
alert("复制成功");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function oCopy()
{
var str = clipboardData.getData("TEXT");
if(str)
{
clipboardData.setData("TEXT", document.getElementById("TextBox1").value);
}
}
{
var str = clipboardData.getData("TEXT");
if(str)
{
clipboardData.setData("TEXT", document.getElementById("TextBox1").value);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function oCopy()
{
txt = document.getElementById("<%=TextBox1.ClientID %>").value;
window.clipboardData.setData("text",txt);
}
{
txt = document.getElementById("<%=TextBox1.ClientID %>").value;
window.clipboardData.setData("text",txt);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询