<script type="text/javascript">
function copyText() { var text = document.getElementById("text").innerText var input = document.getElementById("input")
input.value = text // 修改文本框的内容
input.select() // 选中文本
document.execCommand("copy") // 执行浏览器复制命令
alert("复制成功")
} </script>
<div class="wrapper">
<p id="text">我把你当兄弟你却想着复制我?</p>
<textarea id="input">这是幕后黑手</textarea>
<button onclick="copyText()">copy</button>
</div>
js导入
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery.zclip.min.js"></script>
!上面缺少的文件可以在网上搜索查找。
2.代码
<div class="copybox clearfix">
<div class="copybox-n1 clearfix">
<div style="width:232pxfloat:leftheight:36pxoverflow:hiddenzoom:1">
<input type="text" id="mytxt1" value="点击右侧复制按钮复制" class="n1input">
</div>
<div style="width: 48pxheight: 36pxposition: absolutemargin-left: 232px*margin-left:0px_margin-left: 0">
<button id="copy_input1" class="n1-btn">复制</button>
</div>
</div>
<div class="copybox-n2 clearfix">
<div style="width:232pxfloat:leftheight:36pxoverflow:hiddenzoom:1">
<input type="text" id="mytxt2" value="点击右侧复制按钮复制" class="n1input">
</div>
<div style="width: 48pxheight: 36pxposition: absolutemargin-left: 232px*margin-left:0px_margin-left:0">
<button id="copy_input2" class="n1-btn">复制</button>
</div>
</div>
</div>
<script type="text/javascript">
$(function() {
/*复制*/
$('#copy_input1').zclip( {
path : 'js/ZeroClipboard.swf',
copy : function() {return $('#mytxt1').val()/*复制内容*/},
afterCopy : function() {alert("复制成功")/*复制成功*/}
})
/*复制*/
$('#copy_input2').zclip( {
path : 'js/ZeroClipboard.swf',
copy : function() {return $('#mytxt2').val()/*复制内容*/},
afterCopy : function() {alert("复制成功")/*复制成功*/}
})
})
</script>
3.参考资料
http://www.w3cfuns.com/blog-5458304-5403309.html
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)