gpt4 book ai didi

jquery - Zeroclipboard 悬停问题

转载 作者:行者123 更新时间:2023-11-27 23:52:37 28 4
gpt4 key购买 nike

我尝试改变整个<tr>的颜色在悬停时,但是我无法让它与 Zeroclipboard 一起工作,而且光标也没有改变,有没有人知道如何让它工作?

(至少在我的浏览器中:Google Chrome 版本 37.0.2062.124 m)带有 Zeroclipboard v2.1.6

我的代码如下:

<html>
<head>
<style type="text/css">
.myTABLE { width: 100%; border-collapse: collapse; border: 1px solid black; background-color: lightgrey; }
.myTABLE td { border: 1px solid black; text-align: center; }
.myTABLE tr:hover { background-color: lightgreen; }
.mycopy.zeroclipboard-is-hover { background-color: lightgreen; cursor: hand; }
.mycopy.zeroclipboard-is-active { background-color: #46962B; }
</style>
</head>

<body>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="ZeroClipboard.js"></script>

<br><br><br>
<table class="myTABLE">
<tr><td>test</td><td class="mycopy">Copy 1</td><td>test</td></tr>
<tr><td>test</td><td class="mycopy">Copy 2</td><td>test</td></tr>
<tr><td>test</td><td class="mycopy">Copy 3</td><td>test</td></tr>
<tr><td>test</td><td class="mycopy">Copy 4</td><td>test</td></tr>
<tr><td>test</td><td class="mycopy">Copy 5</td><td>test</td></tr>
<tr><td>test</td><td class="mycopy">Copy 6</td><td>test</td></tr>
</table>

<script type="text/javascript">
var client = new ZeroClipboard( $('.mycopy') );

client.on( 'ready', function(event) {
// console.log( 'movie is loaded' );

client.on( 'copy', function(event) {
event.clipboardData.setData('text/plain', event.target.innerHTML);
} );

client.on( 'aftercopy', function(event) {
console.log('Copied text to clipboard: ' + event.data['text/plain']);
} );
} );

client.on( 'error', function(event) {
// console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message );
ZeroClipboard.destroy();
} );
</script>
</body>
</html>

最佳答案

您忘记将您的 javascript 包含在 jQuery(document).ready(function() ... block 中。或者像我下面的代码中的简短版本 - $(function() ...

点击按钮运行代码。

$(function() {
ZeroClipboard.config({
swfPath: "http://cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.1.6/ZeroClipboard.swf"
});
var client = new ZeroClipboard($('.mycopy'));

client.on('ready', function(event) {

console.log(event.target);
// console.log( 'movie is loaded' );

client.on('copy', function(event) {
event.clipboardData.setData('text/plain', 'test');
});

client.on('aftercopy', function(event) {
console.log('Copied text to clipboard: ' + event.data['text/plain']);
});
});

client.on('error', function(event) {
// console.log( 'ZeroClipboard error of type "' + event.name + '": ' + event.message );
ZeroClipboard.destroy();
});
});
.myTABLE {
width: 100%;
border-collapse: collapse;
border: 1px solid black;
background-color: lightgrey;
}
.myTABLE td {
border: 1px solid black;
text-align: center;
}
.myTABLE tr:hover {
background-color: lightgreen;
}
.mycopy.zeroclipboard-is-hover {
background-color: lightgreen;
cursor: hand;
}
.mycopy.zeroclipboard-is-active {
background-color: #46962B;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/zeroclipboard/2.1.6/ZeroClipboard.js"></script>

<div class="mycopy">yo</div>
<br>
<br>
<br>
<table class="myTABLE">
<tr>
<td>test</td>
<td class="mycopy">Copy 1</td>
<td>test</td>
</tr>
<tr>
<td>test</td>
<td class="mycopy">Copy 2</td>
<td>test</td>
</tr>
<tr>
<td>test</td>
<td class="mycopy">Copy 3</td>
<td>test</td>
</tr>
<tr>
<td>test</td>
<td class="mycopy">Copy 4</td>
<td>test</td>
</tr>
<tr>
<td>test</td>
<td class="mycopy">Copy 5</td>
<td>test</td>
</tr>
<tr>
<td>test</td>
<td class="mycopy">Copy 6</td>
<td>test</td>
</tr>
</table>

关于jquery - Zeroclipboard 悬停问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26067356/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com