pink老师DOM部分 作业

1.世纪佳缘用户名 显示隐藏内容

2.京东关闭广告(二与三差不多直接写了三)

3.新浪下拉菜单(微博即可 )

4.开关灯案例

上码

<style>

      * {

        margin: 0;

        padding: 0;

      }

      li {

        list-style-type: none;

      }

      a {

        text-decoration: none;

        font-size: 14px;

      }

      .nav {

        margin: 100px;

        background-color: antiquewhite;

      }

      .nav > li {

        position: relative;

        float: left;

        width: 80px;

        height: 41px;

        text-align: center;

      }

      .nav li a {

        display: block;

        width: 100%;

        height: 100%;

        line-height: 41px;

        color: #333;

      }

      .nav > li > a:hover {

        background-color: #eee;

      }

      .nav ul {

        display: none;

        position: absolute;

        top: 41px;

        left: 0;

        width: 100%;

        border-left: 1px solid #fecc5b;

        border-right: 1px solid #fecc5b;

      }

      .nav ul li {

        border-bottom: 1px solid #fecc5b;

      }

      .nav ul li a:hover {

        background-color: #fff5da;

      }

    </style>

  </head>

  <body>

    <!-- //作业1 -->

    <input class="sjjy" type="text" value="用户名" />

    <!-- 作业3 -->

    <!-- <div class="box">

      <p class="text">商品</p>

    </div> -->

    <ul class="nav">

      <li>

        <a href="#">微博</a>

        <ul>

          <li>

            <a href="">私信</a>

          </li>

          <li>

            <a href="">评论</a>

          </li>

          <li>

            <a href="">@我</a>

          </li>

        </ul>

      </li>

    </ul>

    <!-- 作业4 -->

    <button id="btn">开关灯</button>

    <script>

      var text = document.querySelector(".sjjy");

      text.onfocus = function () {

        if (text.value === "用户名") {

          text.value = "";

        }

        this.style.color = "#333";

      };

      text.onblur = function () {

        if (text.value === "") {

          text.value = "用户名";

        }

      };

      //作业3

      var nav = document.querySelector(".nav");

      var lis = nav.children;

      for (var i = 0; i < lis.length; i++) {

        lis[i].onmouseover = function () {

          this.children[1].style.display = "block";

        };

        lis[i].onmouseout = function () {

          this.children[1].style.display = "none";

        };

      }

     

      //作业4

      var btn = document.querySelector("#btn");

      var flag = 0;

      btn.onclick = function () {

        if (flag === 0) {

          document.body.style.backgroundColor = "black";

          flag = 1;

        } else {

          document.body.style.backgroundColor = "#fff";

          flag = 0;

        }

      };

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值