为啥我的关闭按钮无效

qq_28256079 2019-08-14 04:46:45
<!doctype html>

<html>

<head>

<meta charset="utf-8">

<title>无标题文档</title>

</head>

<script>

function guanbi(){

var tanc=document.getElementById(tanc);



tanc.style.display="none";

}

</script>

<body>

   

<div class="tanc" style=" display: block;position: absolute; outline: 0; height: auto; width: 976px; top: 109px; left: 387px; ">

<div style=" height: 30px;background: #000000"><span style="font-size:12px;line-height:30px;display:inline-block;padding: 0 40px";>

<!-- 关闭按钮-->

<font color="white">1111111111111111111111111111111111</font><button type="button" id="guanbi" onClick="guanbi()">关闭</button></span>

</div>

<div><iframe src="http://www.baidu.com" frameborder="0" height="632" width="100%"></iframe></div>

</div>

</body>

</html>
...全文
129 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
朽木自雕xmzd 2019-08-14
  • 打赏
  • 举报
回复
兄弟,你这一段代码有一万个错误,我找哭了。 代码如下:自己运行下吧 <!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script> // 这里要加一个window.onload表示在页面加载完成后在加载下面的js代码 window.onload = function(){ // 这里错误用法:function guanbi(){},并且这里不能加var: var guanbi = function(){}错误!!! var guanbi = function(){ // 这里你忘记加双引号"",求求你使用控制台调试一下 var tanc=document.getElementById("tanc"); console.log(tanc); tanc.style.display = "none"; } } </script> </head> <body> <div id="tanc" style=" display: block;position: absolute; outline: 0; height: auto; width: 976px; top: 109px; left: 387px; "> <div style=" height: 30px;background: #000000"><span style="font-size:12px;line-height:30px;display:inline-block;padding: 0 40px"> <!-- 关闭按钮--> <font color="white">1111111111111111111111111111111111</font> <button type="button" onClick="guanbi()">关闭</button> </span> </div> <div><iframe src="http://www.baidu.com" frameborder="0" height="632" width="100%"></iframe> </div> </div> </body> </html>
qq_28256079 2019-08-14
  • 打赏
  • 举报
回复
谢谢大哥,解决了
scscms太阳光 2019-08-14
  • 打赏
  • 举报
回复
var tanc=document.getElementById(tanc);
tanc是什么变量?不存在呀。
天际的海浪 2019-08-14
  • 打赏
  • 举报
回复
var tanc=document.getElementById("tanc"); <div id="tanc" style=" display: block;position: absolute; outline: 0; height: auto; width: 976px; top: 109px; left: 387px; ">

87,993

社区成员

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

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