我正在尝试模拟按钮点击,因此我可以调用
<button id="copy-button" data-clipboard-text="Copy Me!" title="Click to copy me.">Copy to Clipboard</button>
使用https://github.com/zeroclipboard/ZeroClipboard库来操作剪贴板。
我试图在按钮悬停时写入客户端剪贴板。
<button id="copy-button" data-clipboard-text="Copy Me!" title="Click to copy me.">Copy to Clipboard</button>
<script>
var clip = new ZeroClipboard( document.getElementById("copy-button"), {
moviePath: "/js/ZeroClipboard.swf"
} );
clip.on( 'mouseover', function(client) {
clip.setText( "Got in" );
$('#copy-button').simulateClick();
alert("fired");
} );
$.fn.simulateClick = function() {
return this.each(function() {
if('createEvent' in document) {
var doc = this.ownerDocument,
evt = doc.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, doc.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
} else {
this.click(); // IE
}
});
}
</script>
我确实让事件处理程序“mouseover”触发,但我似乎无法模拟按钮点击