用户点击按钮,将制定的文本框的内容全选,并复制到用户的剪贴板
查看演示页面 View Demo 查看全部代码 View Code
第一步:
在<head>区添加以下代码
<style>
.highlighttext{
background-color:yellow;
font-weight:bold;
}
</style>
<script language="Javascript">
/*****************************************************
* Share JavaScript (http://www.ShareJS.com)
* 使用此脚本程序,请保留此声明
* 获取此脚本以及更多的JavaScript程序,请访问 http://www.ShareJS.com
******************************************************/
<!--
//specify whether contents should be auto copied to clipboard (memory)
//Applies only to IE 4+
//0=no, 1=yes
var copytoclip=1
function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
if (document.all&©toclip==1){
therange=tempval.createTextRange()
therange.execCommand("Copy")
window.status="Contents highlighted and copied to clipboard!"
setTimeout("window.status=''",1800)
}
}
//-->
</script>
第二步:
在<body>区添加表单及文本框
<form name="test">
<a class="highlighttext" href="javascript:HighlightAll('test.select1')">Select All</a><br>
<textarea name="select1" rows=10 cols=35 >welcome share javascript - sharejs.com</textarea>
</form>




