浏览器点击复制事件封装

用jq配合附件:
代码格式:

<a href="javascript:;" data-clipboard-snippet>
复制<span class="layuiadmin-span-color"
>dede:field.ispart</span></a>
var clipboardSnippets = new ClipboardJS('[data-clipboard-snippet]', {
			target: function(trigger) {
				console.log(trigger);
			}
		});

引入代码:

/*!
 * clipboard.js v2.0.0
 * https://zenorocha.github.io/clipboard.js
 * 
 * Licensed MIT 脗艩 Zeno Rocha
 */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=3)}([function(t,e,n){var o,r,i;!function(a,c){r=[t,n(7)],o=c,void 0!==(i="function"==typeof o?o.apply(e,r):o)&&(t.exports=i)}(0,function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var o=function(t){return t&&t.__esModule?t:{default:t}}(e),r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),a=function(){function t(e){n(this,t),this.resolveOptions(e),this.initSelection()}return i(t,[{key:"resolveOptions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.action=t.action,this.container=t.container,this.emitter=t.emitter,this.target=t.target,this.text=t.text,this.trigger=t.trigger,this.selectedText=""}},{key:"initSelection",value:function(){this.text?this.selectFake():this.target&&this.selectTarget()}},{key:"selectFake",value:function(){var t=this,e="rtl"==document.documentElement.getAttribute("dir");this.removeFake(),this.fakeHandlerCallback=function(){return t.removeFake()},this.fakeHandler=this.container.addEventListener("click",this.fakeHandlerCallback)||!0,this.fakeElem=document.createElement("textarea"),this.fakeElem.style.fontSize="12pt",this.fakeElem.style.border="0",this.fakeElem.style.padding="0",this.fakeElem.style.margin="0",this.fakeElem.style.position="absolute",this.fakeElem.style[e?"right":"left"]="-9999px";var n=window.pageYOffset||document.documentElement.scrollTop;this.fakeElem.style.top=n+"px",this.fakeElem.setAttribute("readonly",""),this.fakeElem.value=this.text,this.container.appendChild(this.fakeElem),this.selectedText=(0,o.default)(this.fakeElem),this.copyText()}},{key:"removeFake",value:function(){this.fakeHandler&&(this.container.removeEventListener("click",this.fakeHandlerCallback),this.fakeHandler=null,this.fakeHandlerCallback=null),this.fakeElem&&(this.container.removeChild(this.fakeElem),this.fakeElem=null)}},{key:"selectTarget",value:function(){this.selectedText=(0,o.default)(this.target),this.copyText()}},{key:"copyText",value:function(){var t=void 0;try{t=document.execCommand(this.action)}catch(e){t=!1}this.handleResult(t)}},{key:"handleResult",value:function(t){this.emitter.emit(t?"success":"error",{action:this.action,text:this.selectedText,trigger:this.trigger,clearSelection:this.clearSelection.bind(this)})}},{key:"clearSelection",value:function(){this.trigger&&this.trigger.focus(),window.getSelection().removeAllRanges()}},{key:"destroy",value:function(){this.removeFake()}},{key:"action",set:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"copy";if(this._action=t,"copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')},get:function(){return this._action}},{key:"target",set:function(t){if(void 0!==t){if(!t||"object"!==(void 0===t?"undefined":r(t))||1!==t.nodeType)throw new Error('Invalid "target" value, use a valid Element');if("copy"===this.action&&t.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');if("cut"===this.action&&(t.hasAttribute("readonly")||t.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');this._target=t}},get:function(){return this._target}}]),t}();t.exports=a})},function(t,e,n){function o(t,e,n){if(!t&&!e&&!n)throw new Error("Missing required arguments");if(!c.string(e))throw new TypeError("Second argument must be a String");if(!c.fn(n))throw new TypeError("Third argument must be a Function");if(c.node(t))return r(t,e,n);if(c.nodeList(t))return i(t,e,n);if(c.string(t))return a(t,e,n);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")}function r(t,e,n){return t.addEventListener(e,n),{destroy:function(){t.removeEventListener(e,n)}}}function i(t,e,n){return Array.prototype.forEach.call(t,function(t){t.addEventListener(e,n)}),{destroy:function(){Array.prototype.forEach.call(t,function(t){t.removeEventListener(e,n)})}}}function a(t,e,n){return u(document.body,t,e,n)}var c=n(6),u=n(5);t.exports=o},function(t,e){function n(){}n.prototype={on:function(t,e,n){var o=this.e||(this.e={});return(o[t]||(o[t]=[])).push({fn:e,ctx:n}),this},once:function(t,e,n){function o(){r.off(t,o),e.apply(n,arguments)}var r=this;return o._=e,this.on(t,o,n)},emit:function(t){var e=[].slice.call(arguments,1),n=((this.e||(this.e={}))[t]||[]).slice(),o=0,r=n.length;for(o;o<r;o++)n[o].fn.apply(n[o].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),o=n[t],r=[];if(o&&e)for(var i=0,a=o.length;i<a;i++)o[i].fn!==e&&o[i].fn._!==e&&r.push(o[i]);return r.length?n[t]=r:delete n[t],this}},t.exports=n},function(t,e,n){var o,r,i;!function(a,c){r=[t,n(0),n(2),n(1)],o=c,void 0!==(i="function"==typeof o?o.apply(e,r):o)&&(t.exports=i)}(0,function(t,e,n,o){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function c(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function u(t,e){var n="data-clipboard-"+t;if(e.hasAttribute(n))return e.getAttribute(n)}var l=r(e),s=r(n),f=r(o),d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},h=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),p=function(t){function e(t,n){i(this,e);var o=a(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return o.resolveOptions(n),o.listenClick(t),o}return c(e,t),h(e,[{key:"resolveOptions",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.action="function"==typeof t.action?t.action:this.defaultAction,this.target="function"==typeof t.target?t.target:this.defaultTarget,this.text="function"==typeof t.text?t.text:this.defaultText,this.container="object"===d(t.container)?t.container:document.body}},{key:"listenClick",value:function(t){var e=this;this.listener=(0,f.default)(t,"click",function(t){return e.onClick(t)})}},{key:"onClick",value:function(t){var e=t.delegateTarget||t.currentTarget;this.clipboardAction&&(this.clipboardAction=null),this.clipboardAction=new l.default({action:this.action(e),target:this.target(e),text:this.text(e),container:this.container,trigger:e,emitter:this})}},{key:"defaultAction",value:function(t){return u("action",t)}},{key:"defaultTarget",value:function(t){var e=u("target",t);if(e)return document.querySelector(e)}},{key:"defaultText",value:function(t){return u("text",t)}},{key:"destroy",value:function(){this.listener.destroy(),this.clipboardAction&&(this.clipboardAction.destroy(),this.clipboardAction=null)}}],[{key:"isSupported",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:["copy","cut"],e="string"==typeof t?[t]:t,n=!!document.queryCommandSupported;return e.forEach(function(t){n=n&&!!document.queryCommandSupported(t)}),n}}]),e}(s.default);t.exports=p})},function(t,e){function n(t,e){for(;t&&t.nodeType!==o;){if("function"==typeof t.matches&&t.matches(e))return t;t=t.parentNode}}var o=9;if("undefined"!=typeof Element&&!Element.prototype.matches){var r=Element.prototype;r.matches=r.matchesSelector||r.mozMatchesSelector||r.msMatchesSelector||r.oMatchesSelector||r.webkitMatchesSelector}t.exports=n},function(t,e,n){function o(t,e,n,o,r){var a=i.apply(this,arguments);return t.addEventListener(n,a,r),{destroy:function(){t.removeEventListener(n,a,r)}}}function r(t,e,n,r,i){return"function"==typeof t.addEventListener?o.apply(null,arguments):"function"==typeof n?o.bind(null,document).apply(null,arguments):("string"==typeof t&&(t=document.querySelectorAll(t)),Array.prototype.map.call(t,function(t){return o(t,e,n,r,i)}))}function i(t,e,n,o){return function(n){n.delegateTarget=a(n.target,e),n.delegateTarget&&o.call(t,n)}}var a=n(4);t.exports=r},function(t,e){e.node=function(t){return void 0!==t&&t instanceof HTMLElement&&1===t.nodeType},e.nodeList=function(t){var n=Object.prototype.toString.call(t);return void 0!==t&&("[object NodeList]"===n||"[object HTMLCollection]"===n)&&"length"in t&&(0===t.length||e.node(t[0]))},e.string=function(t){return"string"==typeof t||t instanceof String},e.fn=function(t){return"[object Function]"===Object.prototype.toString.call(t)}},function(t,e){function n(t){var e;if("SELECT"===t.nodeName)t.focus(),e=t.value;else if("INPUT"===t.nodeName||"TEXTAREA"===t.nodeName){var n=t.hasAttribute("readonly");n||t.setAttribute("readonly",""),t.select(),t.setSelectionRange(0,t.value.length),n||t.removeAttribute("readonly"),e=t.value}else{t.hasAttribute("contenteditable")&&t.focus();var o=window.getSelection(),r=document.createRange();r.selectNodeContents(t),o.removeAllRanges(),o.addRange(r),e=o.toString()}return e}t.exports=n}])});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
官方主页:http://cres.s28.xrea.com/ MDIE(多文档界面资源管理器)是一个MDI类型的文件管理软件,是代替资源管理器的一个无比强悍的文件管理器 。他支持VBS和JS插件扩展,提供了无限可能。他支持鼠标手势,支持多标签浏览,具有类似浏览器收藏夹功能,具有丰富的搜索模式:在新标签显示搜索结果,搜索模式有:搜索子文件夹、搜索所有分页、选择通配符,搜索最符合,选择文件(可以输入文件的部分名字来自动选中),在工具-MDIE 选项里,勾选“添加至文件的右键菜单”和“替换资源管理器”两项后,可以真正替换掉资源管理器。有详细的个性化选项设置。超赞。 ※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※ 温馨提示:如果选择了“添加至文件的右键菜单”和“替换资源管理器”两项来替代资源管理器,卸载MDIE之前必须把这两项勾掉,否则双击文件夹默认打开方式是MDIE导致无法打开文件夹!如果已经卸载,可以重装后在勾掉这两项,然后卸载! ※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※ MDIE的所有设置均保存在注册表[HKEY_CURRENT_USER\software\MDIE2]主键之下。 安装时根据提示确认导入注册表文件,下面的设置就会生效。如果注册表被锁定了,运行程序组里面的接触注册表编辑限制就行了。 mdie设置说明:工具→mdie选项→ 1、常规标签: √记住窗口位置 √添加至文件的右键菜单 √替代资源管理器 √关闭时,最小化到系统托盘 2、列表窗口: 默认样式→列表,文字宽度222,列表宽度444 3、分页标签: 右键点击→选择关闭(这个选项很好用) shift+右键点击→右键功能菜单 ctrl+右键点击→右键功能菜单 滚轮点击→分页操作菜单 双击→关闭 4、窗口动作: 点击收藏夹:打开→shift,新分页→无,这样可以保证单击收藏夹时打开新标签。 点击链接:打开→shift,新分页→无,这样可以保证单击链接时打开新标签。 点击地址栏:打开→shift,新分页→无,这样可以保证在地址栏输入的时候打开新标签。 滚轮点击列表窗口→新标签。 5、启动时: √恢复上次结束时的分页 6、在搜索结果栏目中右击搜索到的项目没有右击关联菜单,不能右击→打开所在的文件夹。但是我们可以通过鼠标手势来实现,具体办法是:工具→鼠标手势→工具→其他命令→在新分页中打开→场所选择搜索栏→动作选择R→即可。那么我们就可以在搜索的结果中右击后向右拖动来实现在我的电脑中右击打开所在文件夹那种效果。MDIE鼠标手势真的无所不能无比强大,慢慢研究吧! 7、建议把硬盘CDEF等及桌面、我的电脑放到链接栏,例如打开F盘→收藏→添加到链接。 删除的方法是:按CTRL+I或者单击查看→侧边栏→链接栏→选择F→删除。 8、已有的鼠标手势:后退R←,前进R→,搜索栏中在新分页打开R→,向上一级R↑或双击空白处,刷新R↓↑,下一分页Rwheel↓,上一分页Rwheel↑,关闭标签R↓→,恢复最后关闭的标签R→←,显示隐藏文件R↓,关闭全部分页R↓←,隐藏已知文件类型的扩展名R→↓,在当前文件夹打开CMD窗口R↑→,高级更名R↑↓,复制选中文件路径并弹出对话框↑←。 几个MDIE的插件: 单击MDIE工具→扩展功能→添加脚本→MDIE隐藏已知文件类型的扩展名.vbs→确定之后,你可以为他设定一个鼠标手势,我设置的是R→↓。 //MDIE隐藏已知文件类型的扩展名.vbs //Dim WSHShell WSHShell=new ActiveXObject("WScript.Shell") MDIE.Command(5100) //WSHShell.SendKeys ("%TF") //MDIE.Sleep(600) WSHShell.SendKeys ("^{TAB}{TAB}{DOWN 14}") WSHShell.SendKeys (" {TAB}{TAB} ") MDIE.Sleep(300) WSHShell.SendKeys ("{BACKSPACE}") MDIE.Sleep(300) WSHShell.SendKeys ("%{LEFT}") //MDIE.Command(5207) //FolderView.refresh(0) //MDIE显示隐藏文件.vbs,这个不用VBS也行,直接把工具→快速选项设置→显示隐藏文件→用鼠标手势设置为R↓就行了。 MDIE.Command(5105) //在当前文件夹打开cmd窗口.js,这个网友发布的,然后把它设置为鼠标手势R↑→,看个人爱好。 var shell = new ActiveXObject("WScript.Shell"); shell.Run('cmd /K @cd /d '+FolderView.Path +'"'); //备份MDIE注册表项目.js var d = new Date(); var s = d.getFullYear() + "-"; s += (d.getMonth() + 1) + "-"; s += d.getDate() + "-"; s += d.getHours() + "-"; s += d.getMinutes() + ".reg"; var WshShell = new ActiveXObject("WScript.Shell"); WshShell.Exec("Regedit /E "+ s +" HKEY_CURRENT_USER\\software\\MDIE2"); //查找目标.js var WshShell = new ActiveXObject("WScript.Shell"); var oShellLink = WshShell.CreateShortcut(FolderView.FocusItem.Path); FolderView.open(oShellLink.TargetPath); //复制选中文件路径.vbs MDIE.Clipboard(FolderView.FocusItem.Path); //复制选中文件路径并弹出对话框.js MDIE.Clipboard(FolderView.FocusItem.Path); MDIE.echo(MDIE.Clipboard); //新建txt文件.js objFso = new ActiveXObject( "Scripting.FileSystemObject" ); objWsh = new ActiveXObject( "WScript.Shell" ); strDTxtReg = objWsh.RegRead( "HKCR\\.txt\\" ); strTxtReg = objWsh.RegRead( "HKCR\\" + strDTxtReg + "\\" ); strFileName = FolderView.Path + "\\新建" + strTxtReg + "\.txt"; for ( i = 2 ; objFso.FileExists( strFileName ) ; i++ ) { strFileName = FolderView.Path + "\\新建" + strTxtReg + " (" + i + ")\.txt"; } objFso.CreateTextFile( strFileName ); FolderView.Refresh(2); MDIE.Command( 5226 ); MDIE.Command( 5206 ); //用资源管理器打开当前窗口.js var viewerPath = "C:\\WINDOWS\\explorer.exe"; var shell = new ActiveXObject("WScript.Shell"); shell.Run('"' + viewerPath + '" "' + FolderView.Path+ '"', 1, false); 运行js提示库没有注册错误8002801d的解决办法: 这个错误主要是因为windows scripts版本较低,在微软官网搜索windows scripts,选择scr56chs.exe下载后安装即可。 http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=376d98b6-67cf-4473-9b7d-f635292a286f&displaylang=zh-cn http://download.microsoft.com/download/winscript56/Install/5.6/W982KMe/CN/scr56chs.exe
Uniapp 中可以使用组件来封装 ListCell,并在组件中设置点击事件。以下是示例代码: 1. 创建一个自定义组件,例如 MyListCell.vue。 ``` <template> <view class="my-list-cell" @click="handleClick"> <text>{{ title }}</text> <text>{{ content }}</text> </view> </template> <script> export default { props: { title: { type: String, default: '' }, content: { type: String, default: '' } }, methods: { handleClick() { // 处理点击事件 this.$emit('click', { title: this.title, content: this.content }) } } } </script> <style> .my-list-cell { padding: 10px; border-bottom: 1px solid #ccc; } </style> ``` 2. 在页面中使用 MyListCell 组件,并监听点击事件。 ``` <template> <view> <my-list-cell v-for="(item, index) in list" :key="index" :title="item.title" :content="item.content" @click="handleCellClick"></my-list-cell> </view> </template> <script> import MyListCell from '@/components/MyListCell' export default { components: { MyListCell }, data() { return { list: [ { title: '标题1', content: '内容1' }, { title: '标题2', content: '内容2' }, { title: '标题3', content: '内容3' } ] } }, methods: { handleCellClick(data) { console.log('点击了列表项:', data) } } } </script> ``` 在以上代码中,MyListCell 组件接收两个 props:title 和 content,用于渲染列表项的标题和内容。组件内部监听了点击事件,并通过 $emit 方法触发了一个自定义事件 click,将当前列表项的 title 和 content 作为参数传递出去。在页面中使用 MyListCell 组件时,通过 v-for 循环渲染出多个列表项,并通过 @click 监听了组件的点击事件,触发了 handleCellClick 方法。在 handleCellClick 方法中,可以处理点击事件并获取到当前列表项的数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值