Javascript:点击获取并在剪贴板上分配值

时间:2017-06-20 08:14:43

标签: javascript jquery copy-paste

我在使用粘贴事件时有这行代码:

//This works
document.addEventListener('paste', e => {
  console.log("e.clipboardData.getData('text/plain');", 
               e.clipboardData.getData('text/plain'));
});

但是我需要复制并粘贴一个按钮,所以:

//Not Working
jQuery(buttonId).click(e => {
  console.log("e.clipboardData.getData('text/plain');", 
               e.clipboardData.getData('text/plain'));
});

1 个答案:

答案 0 :(得分:-2)

Try this :

   $("#buttonId").on("click",e => {
   console.log("e.clipboardData.getData('text/plain');", 
               e.clipboardData.getData('text/plain'));
   });

$ symbol is used instead of jQuery keyword , '#' is id selector in jQuery