Zclip插件不能复制文本。
<head>
<script type = "text/javascript" src = "jquery.min.js"></script>
<script type = "text/javascript" src = "jquery.zclip.min.js"></script>
</head>
<button id = "copy-description">132</button>
<p id = "description">123456789132456789</p>
<script type = "text/javascript">
$(document).ready(function(){
$('#copy-description').click(function(){
$('#copy-description').zclip({
path:'ZeroClipboard.swf',
copy:function(){return $('p#description').val();}
});
});
});
</script>
当我点击按钮时,我的剪贴板不会改变。我尝试使用jQuery v1.11.1和v 1.6 谢谢你的帮助。
答案 0 :(得分:1)
这应该有效。我删除了HTML中id
标记的空间。
<button id="copy-description">132</button>
<p id="description">123456789132456789</p>
然后将.val()
更改为.text()
,因为我们从div而不是表单元素中获取文本。
$(document).ready(function(){
$('#copy-description').click(function(){
$('#copy-description').zclip({
path:'http://ajax.cdnjs.com/ajax/libs/zclip/1.1.2/ZeroClipboard.swf', //you can change this back to your local version, I had to to this for testing.
copy:function(){
return $('#description').text(); //changed .val() to .text()
}
});
});
});