博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
原生JS解决复制文本或内容到剪贴板...追加解决jsp中js拼接onclick非数字情况报错的问题
阅读量:2072 次
发布时间:2019-04-29

本文共 1364 字,大约阅读时间需要 4 分钟。

vue中很多人推荐了clipboard,但是我这边的项目由于是jsp和vue混编,所以我只能考虑一种通用解决方案

 

所以,我在vue和jsp中都用了同一种写法

 

jsp中

vue中

Application No. : {
{vue.ticketNo}}
methods:{ //复制 copyText: function(text) { console.log(text); var textArea = document.createElement("textarea"); textArea.style.position = 'fixed'; textArea.style.top = '0'; textArea.style.left = '0'; textArea.style.width = '2em'; textArea.style.height = '2em'; textArea.style.padding = '0'; textArea.style.border = 'none'; textArea.style.outline = 'none'; textArea.style.boxShadow = 'none'; textArea.style.background = 'transparent'; textArea.value = text; document.body.appendChild(textArea); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'Successful copy to clipboard' : 'The browser does not support click-and-copy to clipboard'; alert(msg); } catch (err) { alert('The browser does not support click-and-copy to clipboard'); } document.body.removeChild(textArea); },}

完美解决,而且如果浏览器不兼容会弹出不支持的语句

 

追加一个解决onclick事件报错的问题,动态jsp拼接onclick事件报错

如果是纯数字不会报错,但是如果是字符串会有undifined的情况,导致onclick点不出效果

$('td:eq(1)', row).append("");

特殊说明

οnclick=\"copyText('"+data.ticketNo+"')\"

不这么写,浏览器不认,不知道为啥,希望看到的大神帮忙回复下

转载地址:http://eupmf.baihongyu.com/

你可能感兴趣的文章
【MyBatis学习06】输入映射和输出映射
查看>>
【MyBatis学习07】动态sql
查看>>
【MyBatis学习08】高级映射之一对一查询
查看>>
【MyBatis学习09】高级映射之一对多查询
查看>>
【MyBatis学习10】高级映射之多对多查询
查看>>
【MyBatis学习11】MyBatis中的延迟加载
查看>>
【MyBatis学习12】MyBatis中的一级缓存
查看>>
【MyBatis学习13】MyBatis中的二级缓存
查看>>
【MyBatis学习14】MyBatis和Spring整合
查看>>
【MyBatis学习15】MyBatis的逆向工程生成代码
查看>>
Java 中 final、finally 和 finalize 使用总结
查看>>
volatile关键字解析
查看>>
单例模式的八种写法比较
查看>>
比较常见的数据库SQL面试题以及答案
查看>>
MySQL与Oracle的区别
查看>>
关于Oracle数据库优化的几点总结
查看>>
69道Spring面试题和答案
查看>>
40个Java多线程问题总结
查看>>
Oracle数据库面试题
查看>>
java面试中的智力题
查看>>