表单提交时自动复制内容到剪贴板的js代码
时间:2021-11-19 13:21:26|栏目:JavaScript代码|点击: 次
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>交时自动复制到剪贴板</title>
</head>
<script language="JavaScript">
/*功能:提交时自动复制到剪贴板 */
function copyText(obj) {
ie = (document.all)? true:false
if (ie){
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}
}
function autocopy() {
if (this.document.formname.isautocopy.checked) {
copyText(this.document.formname.icontent);
}
}
</script>
<body>
<form action="" method="post" name="formname" onsubmit="autocopy();">
<textarea name="icontent" rows="4" cols="50"></textarea><br>
<input name="isautocopy" checked="checked" value="1" type="checkbox" />
提交时复制内容到剪贴板<br/><input type="submit" value="提交" /> </form>
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>交时自动复制到剪贴板</title>
</head>
<script language="JavaScript">
/*功能:提交时自动复制到剪贴板 */
function copyText(obj) {
ie = (document.all)? true:false
if (ie){
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
rng.collapse(false);
}
}
function autocopy() {
if (this.document.formname.isautocopy.checked) {
copyText(this.document.formname.icontent);
}
}
</script>
<body>
<form action="" method="post" name="formname" onsubmit="autocopy();">
<textarea name="icontent" rows="4" cols="50"></textarea><br>
<input name="isautocopy" checked="checked" value="1" type="checkbox" />
提交时复制内容到剪贴板<br/><input type="submit" value="提交" /> </form>
</body>
</html>