我有一个可视树,我必须应用剪切,复制和粘贴功能来剪切顶点,复制顶点并粘贴它。 我希望代码在IE中工作。 有人可以帮我编写java脚本中的剪切,复制和粘贴代码。
先谢谢
答案 0 :(得分:2)
document.addEventListener('beforecopy', function(e){
if(weHaveDataToCopy()){ // use your web app's internal logic to determine if something can be copied
e.preventDefault(); // enable copy UI and events
}
});
document.addEventListener('copy', function(e){
e.clipboardData.setData('text/plain', 'Hello, world!');
e.clipboardData.setData('text/html', '<b>Hello, world!</b>');
e.preventDefault(); // We want our data, not data from any selection, to be written to the clipboard
});
document.addEventListener('paste', function(e){
if(e.clipboardData.types.indexOf('text/html') > -1){
processDataFromClipboard(e.clipboardData.getData('text/html'));
e.preventDefault(); // We are already handling the data from the clipboard, we do not want it inserted into the document
}
});