0

我正在尝试模拟按钮点击,所以我可以打电话

<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>

我确实让事件处理程序“鼠标悬停”触发,但我似乎无法模拟按钮单击

4

0 回答 0