JavaScript实现复制或剪切内容到剪贴板功能的方法_.docx

上传人:PIYPING 文档编号:11644423 上传时间:2021-08-27 格式:DOCX 页数:7 大小:12.79KB
返回 下载 相关 举报
JavaScript实现复制或剪切内容到剪贴板功能的方法_.docx_第1页
第1页 / 共7页
JavaScript实现复制或剪切内容到剪贴板功能的方法_.docx_第2页
第2页 / 共7页
JavaScript实现复制或剪切内容到剪贴板功能的方法_.docx_第3页
第3页 / 共7页
JavaScript实现复制或剪切内容到剪贴板功能的方法_.docx_第4页
第4页 / 共7页
JavaScript实现复制或剪切内容到剪贴板功能的方法_.docx_第5页
第5页 / 共7页
亲,该文档总共7页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《JavaScript实现复制或剪切内容到剪贴板功能的方法_.docx》由会员分享,可在线阅读,更多相关《JavaScript实现复制或剪切内容到剪贴板功能的方法_.docx(7页珍藏版)》请在三一文库上搜索。

1、JavaScript实现复制或剪切内容到剪贴板功能的方法_ 这篇文章主要介绍了JavaScript实现复制或剪切内容到剪贴板功能的方法,我们平常看到的网页上许多一键复制功能就是如此实现,需要的伴侣可以参考下 项目中需要实现一个点击按钮复制链接的功能,网上看到的几款插件,ZeroClipboard是通过flash实现的复制功能,随着越来越多的提议废除flash,能不能通过JS来实现复制剪切呢,今日分享一个兼容IE7扫瞄器复制的插件给大家,支持用法javascript实现复制、剪切和粘贴。 方法。 复制 var copy = new clipBoard(document.getElementByI

2、d(data), beforeCopy: function() , copy: function() return document.getElementById(data).value; , afterCopy: function() ); 复制将自动被调用,假如你想要自己调用: var copy = new clipBoard(document.getElementById(data); copy.copyd(); document.getElementById(data) :要猎取的对象, 你也可以用法jQuery $(#data) 剪切 基本上与复制的实现方法相同: var cut =

3、 new clipBoard(document.getElementById(data), beforeCut: function() , cut: function() return document.getElementById(data).value; , afterCut: function() ); 或者 var cut = new clipBoard(document.getElementById(data); cut.cut(); paste var paste = new clipBoard(document.getElementById(data), beforePaste:

4、 function() , paste: function() return document.getElementById(data).value; , afterPaste: function() ); 或者 var paste = new clipBoard(document.getElementById(data); paste.paste(); 完整代码: (function(name, fun) if (typeof module != undefined module.exports) module.exports = fun(); else if (typeof define

5、= function define.amd) define(fun); else thisname = fun(); )(clipBoard, function() use strict; function clipBoard(tar, options) this.options = options | ; this.tar = tar0 | tar; / if options contain copy, copy will be applied soon if (this.options.copy) this.copyd(); if(this.options.cut) this.cut();

6、 if(this.options.paste) this.paste(); clipBoard.prototype.copyd = function(value) / before the copy it will be called, you can check the value or modify the value if (this.options.beforeCopy) this.options.beforeCopy(); / if the options set copy function, the value will be set. then get the paramer v

7、alue. / above all, if the value is null, then will be set the tar of value value = value | this.tar.value | this.tar.innerText; if (this.options.copy) value = this.options.copy(); / for modern browser if (document.execCommand) var element = document.createElement(SPAN); element.textContent = value;

8、document.body.appendChild(element); if (document.selection) var range = document.body.createTextRange(); range.moveToElementText(element); range.select(); else if (window.getSelection) var range = document.createRange(); range.selectNode(element); window.getSelection().removeAllRanges(); window.getSelection().addRange(range); document.execCommand(copy); element.remove ? element.remove() : element.removeNode(true); / for ie if (window.clipboardData) window.clipboardData.setData(text, value); / after copy if (this.options.afterCopy) this.options.afterCopy(); ; .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1