如何将某个对象里的内容全部复制到剪切板? 如何将某个对象里的内容全部复制到剪切板?就像论坛提交的时候,把帖子内容复制到剪切板。万一没发成功,可以粘贴。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <input type="text" id="test" value="content"><input type="button" value="copy" onclick="copyText(document.getElementById('test'))"><script>function copyText(obj) { obj.select(); clipboardData.setData("text",obj.createTextRange().text); alert(clipboardData.getData("text"));}</script> 给你一段js代码吧.刚给另外一个人弄的<!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><label name="testtext" id="testtext" onclick="copycode(this);">test copy functionsdfsdf sdfsd</label><script type="text/javascript">function copycode(obj) { var rng = document.body.createTextRange(); rng.moveToElementText(obj); rng.scrollIntoView(); rng.select(); rng.execCommand("Copy"); window.alert("代码已复制到剪贴板中!"); rng.collapse(false); }</script></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></head><body><script type="text/javascript">function copyText(obj) { obj.select(); clipboardData.setData("text",obj.createTextRange().text); alert(clipboardData.getData("text"));}</script><input id="content" name="content" type="text" /><input name="btnSubmit" type="submit" onclick="javascript:copyText(document.getElementById('content'));" value="提交" /></body></html>UP 如何点击某个链接,显示或隐藏iframe 自动关闭确认框 给隐藏域赋值 类QQ和MSN的右下角消息弹出组件(功能更全)【20071022】 调用 其他iframe里的元素 用javascript如何实现这样的下载? 怎么让JS延迟10S执行? 网页中activex事件的参数如果是对象如何解析? 层的显示与隐藏急----请高手赐教 请问按shift键和按ctrl键的事件分别是什么? 点击button,为什么没有效果呢?请大侠帮忙啊!! 如何在连接后边传的值中带&符号
<input type="button" value="copy" onclick="copyText(document.getElementById('test'))">
<script>
function copyText(obj) {
obj.select();
clipboardData.setData("text",obj.createTextRange().text);
alert(clipboardData.getData("text"));
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<label name="testtext" id="testtext" onclick="copycode(this);">test copy functionsdfsdf sdfsd
</label>
<script type="text/javascript">function copycode(obj) {
var rng = document.body.createTextRange();
rng.moveToElementText(obj);
rng.scrollIntoView();
rng.select();
rng.execCommand("Copy");
window.alert("代码已复制到剪贴板中!");
rng.collapse(false);
}
</script></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>
</head><body>
<script type="text/javascript">function copyText(obj) {
obj.select();
clipboardData.setData("text",obj.createTextRange().text);
alert(clipboardData.getData("text"));
}
</script>
<input id="content" name="content" type="text" />
<input name="btnSubmit" type="submit" onclick="javascript:copyText(document.getElementById('content'));" value="提交" />
</body>
</html>UP