为了账号安全,请及时绑定邮箱和手机立即绑定

这样为什么不行?通过js改变样式

<!DOCTYPE html />

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

<style>

#div1{width:100px;

height:100px;

background:red

display:none;}

<script>

window.onload=function(){

var odiv1=document.getElementById("div1")

odiv1.style.display="block";


}

</script>

</style>

</head>


<body>

<div id="div1">

</div>

</body>

</html>


正在回答

6 回答

<!DOCTYPE html >

<html>

  <head>

    <title>MyHtml.html</title>

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

        <style type="text/css">

          #div1{

            border:1px solid gray;

            width:100px;

            height:100px;

            display: block;

          }

        </style>    

        <script type="text/javascript">

        function change(){  

         var d= document.getElementById("div1");

         d.style.display='none'; 

        }

        function reset(){

         var d= document.getElementById("div1");

         d.style.display='block'; 

        }

        </script> 

  </head>

  

  <body>

      <div  id="div1" onclick="change()" >测试</div>

      <button onclick="reset()" >恢复</button>

  </body>

</html>


0 回复 有任何疑惑可以回复我~
#1

qq_错过的_0

你可以参考下我写的
2017-01-07 回复 有任何疑惑可以回复我~
#2

狂四郎 提问者

非常感谢!
2017-03-09 回复 有任何疑惑可以回复我~
var odiv1=document.getElementById("div1")

少了个分号,还有就是style标签的问题,别把script包在里面

0 回复 有任何疑惑可以回复我~

怎么感觉你好多标签都不成对?

0 回复 有任何疑惑可以回复我~

<style></style>标签是成对用的.

0 回复 有任何疑惑可以回复我~

display设置为none不显示,把dispay的值改成block或inline.

0 回复 有任何疑惑可以回复我~
#1

狂四郎 提问者

我用js改变样式了,为什么不行?
2016-12-29 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

这样为什么不行?通过js改变样式

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信