求助:每次点击复制按钮文本前面总有'document.write',麻烦各位帮看看哪里出错了,不胜感激

热心网友笃信 2019-05-09 02:10:14
<!DOCTYPE html>

<html>
<head><meta charset="utf-8">

<style>
#biao1{
display: none !important;
}
</style>

<script type="text/javascript">
var arr_wx = [
'wx11','wx22','wx33','wx44','wx55','wx66','wx77','wx88','wx99','wx10'
];
var wx_index = Math.floor((Math.random()*arr_wx.length));
var bdorderwx = arr_wx[wx_index];
</script>
</head>

我是随机微信号<span><script type="text/javascript">document.write(bdorderwx);</script></span>

<div cols="20" id="biao1" >
<span><script type="text/javascript">document.write(bdorderwx);</script></span>
</div>

<script type="text/javascript">

function copyUrl2()
{
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('复制成功');
window.location.href="weixin://";
}
</script>

<input type="button" onClick="copyUrl2()" value="点击复制代码" />
</html>
...全文
181 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
stherix 2019-05-09
  • 打赏
  • 举报
回复
在js里直接改span的innerText吧,不要用doucment。write写
追热 2019-05-09
  • 打赏
  • 举报
回复
不推荐使用document.write
热心网友笃信 2019-05-09
  • 打赏
  • 举报
回复
引用 5 楼 usecf 的回复:
<!DOCTYPE html> <html> <head><meta charset="utf-8"> <style> #biao1{ display: none !important; } </style> <script type="text/javascript"> var arr_wx = [ 'wx11','wx22','wx33','wx44','wx55','wx66','wx77','wx88','wx99','wx10' ]; window.onload= function() { var wx_index = Math.floor((Math.random()*arr_wx.length)); var bdorderwx = arr_wx[wx_index]; document.getElementById("firstSpan").innerText = bdorderwx; } </script> </head> 我是随机微信号<span id="firstSpan"></span> <div cols="20" id="biao1" > <span id="secondSpan"></span> </div> <script type="text/javascript"> function copyUrl2() { var Url2=document.getElementById("biao1").innerText; var oInput = document.createElement('input'); oInput.value = document.getElementById("firstSpan").innerText;//Url2; document.body.appendChild(oInput); oInput.select(); document.execCommand("Copy"); oInput.className = 'oInput'; oInput.style.display=''; document.getElementById("secondSpan").innerText = document.getElementById("firstSpan").innerText; alert('复制成功'); // window.location.href="weixin://"; } </script> <input type="button" onClick="copyUrl2()" value="点击复制代码" /> </html>
非常感谢
usecf 2019-05-09
  • 打赏
  • 举报
回复
<!DOCTYPE html>

<html>
<head><meta charset="utf-8">

<style>
#biao1{
display: none !important;
}
</style>

<script type="text/javascript">
var arr_wx = [
'wx11','wx22','wx33','wx44','wx55','wx66','wx77','wx88','wx99','wx10'
];
window.onload= function()
{
var wx_index = Math.floor((Math.random()*arr_wx.length));
var bdorderwx = arr_wx[wx_index];
document.getElementById("firstSpan").innerText = bdorderwx;

}


</script>
</head>

我是随机微信号<span id="firstSpan"></span>

<div cols="20" id="biao1" >
<span id="secondSpan"></span>
</div>

<script type="text/javascript">

function copyUrl2()
{
var Url2=document.getElementById("biao1").innerText;
var oInput = document.createElement('input');
oInput.value = document.getElementById("firstSpan").innerText;//Url2;
document.body.appendChild(oInput);
oInput.select();
document.execCommand("Copy");
oInput.className = 'oInput';
oInput.style.display='';
document.getElementById("secondSpan").innerText = document.getElementById("firstSpan").innerText;
alert('复制成功');
// window.location.href="weixin://";
}
</script>

<input type="button" onClick="copyUrl2()" value="点击复制代码" />
</html>
热心网友笃信 2019-05-09
  • 打赏
  • 举报
回复
引用 1 楼 追热 的回复:
不推荐使用document.write
新手入门,不知道应该怎么改,希望您能多指教,感谢
热心网友笃信 2019-05-09
  • 打赏
  • 举报
回复
引用 1 楼 追热 的回复:
不推荐使用document.write
还是不太明白怎样来改,可以详细说一下吗,麻烦您了

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧