复制到剪贴板 - 在JSFiddle上工作但不在本地工作

时间:2014-06-30 23:20:19

标签: jquery clipboard zeroclipboard

我试图实现代码来复制剪贴板中项目的内容。它适用于JSFiddle

HTML

<p id="description">Text to copy</p>
<a href="#" id="copy">Click here to copy</a>

JS

$(document).ready(function () {
    $('#copy').zclip({
        path: 'http://www.steamdev.com/zclip/js/ZeroClipboard.swf',
        copy: $('#description').text(),
        beforeCopy: function () {
            $('#description').css('background', 'yellow');
        },
        afterCopy: function () {
            $('#description').css('background', 'green');
        }
    });
});

但是如果我创建具有相同内容的html文件,它就不起作用......

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>demo</title>
</head>
<body>
<p id="description">Text to copy</p>
<a href="#" id="copy">Click here to copy</a>
<script type="text/javascript" src="http://code.jquery.com/jquery-git2.js"></script>
<script type="text/javascript" src="http://www.steamdev.com/zclip/js/jquery.zclip.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    $('#copy').zclip({
        path: 'http://www.steamdev.com/zclip/js/ZeroClipboard.swf',
        copy: $('#description').text(),
        beforeCopy: function () {
            $('#description').css('background', 'yellow');
        },
        afterCopy: function () {
            $('#description').css('background', 'green');
        }
    });
});
</script>
</body>
</html>

为什么?

0 个答案:

没有答案