第一種方式:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
</head>
<body>
<form>
<p>
<input name=txtSearch type="text" value="">
<input type=button value=Copy2Clip onclick='javascript: var textRange=txtSearch.createTextRange(); textRange.execCommand("Copy")'>
</p>
<p>
<input name="copyto" type="text" >
<input type=button value=PastefromClip onclick='javascript: var textRange=copyto.createTextRange(); textRange.execCommand("Paste")'>
</p>
</form>
</body>
</html>
第二種方式:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<script language="javascript">
/*window.clipboardData.setData("Text","你的內容");
var retVal=window.clipboardData.getData("Text");
alert(retVal);*/
</script>
</head>
<body>
<input type="text" id="txt"/>
<input type="button" value="複製" onclick="javascript:window.clipboardData.setData('Text',document.getElementById('txt').value);"/>
<input type="button" value="得到剪貼簿中的值" onclick="javascript:alert(window.clipboardData.getData('Text'));"/>
</body>
</html>