Mar
23
2020
JavaScript 复制功能代码,兼容多浏览器
作者:
绝缘体.. 发布:
2020-03-23 09:47 分类:
未分类 阅读:
抢沙发
分享一段利用 JavaScript 实现复制功能的代码,兼容多浏览器,兼容IE和火狐浏览器。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>JavaScript 复制功能代码,兼容多浏览器</title>
</head>
<script type="text/javascript">
function copyValue(Url2) {
//var Url2 = document.getElementById("biao1").innerText;
var oInput = document.createElement('input');
oInput.value = Url2;
document.body.appendChild(oInput);
oInput.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
oInput.className = 'oInput';
oInput.style.display = 'none';
alert('复制成功');
}
</script>
<div class="phoinfo">
贴图地址:<input value="<a href='http://www.phpernote.com/'>www.phpernote.com</a>" type="text" size="65"/>
<input type="button" onClick="copyValue('<a href=\'http://www.phpernote.com/\'>www.phpernote.com</a>');" value="复制"/>
</div>
</body>
</html>
示例如下:
贴图地址:
微信扫一扫,打赏作者吧~