`
hsys
  • 浏览: 286403 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Jquery 实现复制到剪贴板

阅读更多
不兼容Firefox

<html>
<head>
<title>Selector</title>
<script type='text/javascript' src="jquery/jquery-1.3.1.js"></script>
<script type='text/javascript' src="jquery.copy.js"></script>
<script language="javascript">
	$(document).ready(function(){
		 
		$("#copy").click(function(){
			var text = $("#text").val()
			alert(text);
			$.copy(text);
			alert("成功到剪贴板");
		});
		
	});
</script> 

<body>
	<p><b>Values: </b></p> 
	<br>
	<form>
	  <textarea name="name" id="text" rows="5" >hello world</textarea>
	  
	  <input type="button" value="复制" id="copy" />
	  
	</form>	
</body>
</html>
分享到:
评论
1 楼 远去的渡口 2013-05-09  
我用你的这方法,根本就没有复制到剪切板。。。
jquery.copy.js我试了两个版本的,都不行,我是奇怪你这样写为啥就行呢??
后来我是换了最原始的方法完成的:
<script type="text/javascript">
{literal}

$(function() {
        $("#copy").click(function(){
            var text = $("#urlStr").html();
            window.clipboardData.setData('text',text);
            alert("成功到剪贴板");
        });

});



{/literal}
</script>

相关推荐

Global site tag (gtag.js) - Google Analytics