ASP.NET采用JS将字符串写到剪切板上
1 function copyToClipboard(copyControl)
2 {
3 var obj=document.getElementById(copyControl);
4 if(obj!=null)
5 {
6 var clipBoardContent=obj.value;
7 obj.select();
8 window.clipboardData.setData("Text",clipBoardContent);
9 }
10 else
11 {
12 alert("Error!");
13 }
14 }
2 {
3 var obj=document.getElementById(copyControl);
4 if(obj!=null)
5 {
6 var clipBoardContent=obj.value;
7 obj.select();
8 window.clipboardData.setData("Text",clipBoardContent);
9 }
10 else
11 {
12 alert("Error!");
13 }
14 }
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>剪切板测试</title>
<script type="text/javascript" src="JScript.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="md_id_board" runat="server" Text = "请复制到剪切板"></asp:TextBox>
<asp:Button ID="Button3" runat="server" Text="测试" OnClientClick = "copyToClipboard('md_id_board');" onclick="Button3_Click"/>
</div>
</form>
</body>
</html>
posted on 2011-09-23 15:21 WildFlower 阅读(1217) 评论(0) 编辑 收藏 举报