博主信息
博文 17
粉丝 0
评论 0
访问量 14658
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
选项卡 客服问答 2018-3-30
一片叶
原创
697人浏览过

选项卡

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>选项卡</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    ul,list{
      list-style: none;
    }
    a{
      text-decoration: none;
      color: black;
    }
    a:hover{
      text-decoration: underline;
    }
    .box{
      margin: 20px auto;
      width: 200px;
      height: 200px;
      border: 1px solid black;
      text-align: center;
    }
    .box>ul{
      clear: both;
      overflow: hidden;
    }
    .box>ul li.on{/* 写这么长是为了增加权重 */
      border-top: 2px solid red;
      border-bottom: 1px solid white;
    }

    .box>ul li{
      float: left;
      width: 60px;
      height: 30px;
      border-top: 2px solid transparent;
      border-right: 1px solid black;
      border-bottom: 1px solid black;
      line-height: 30px;
    }
 
    .box> div{
      margin: 10px 10px;
      width: 100%;
      height: 150px;
      text-align: left;
    }
    .off{
      display: none;
    }
    .block{
      display: block;
    }

  </style>
</head>
<body>
  <div class="box">
      <ul class="ul">
        <li class="on">卡一</li>
        <li>卡二</li>
      </ul>
    <div class="block">
      <ul>
        <li><a href="##">今天天气不错</a></li>
        <li><a href="##">今天天气不错</a></li>
        <li><a href="##">今天天气不错</a></li>
        <li><a href="##">今天天气不错</a></li>
        <li><a href="##">今天天气不错</a></li>
        <li><a href="##">今天天气不错</a></li>
      </ul>
    </div>
    <div class="off">
      <ul>
        <li><a href="##">明天要出去玩</a></li>
        <li><a href="##">明天要出去玩</a></li>
        <li><a href="##">明天要出去玩</a></li>
        <li><a href="##">明天要出去玩</a></li>
        <li><a href="##">明天要出去玩</a></li>
        <li><a href="##">明天要出去玩</a></li>
      </ul>
    </div>
  </div>
</body>
<script>
  var li = document.querySelectorAll(".ul li");
  var od = document.querySelector(".box");
  var odiv = od.querySelectorAll("div");
  for(var i =0;i<li.length; i++){
    li[i].index = i;
    li[i].onmouseover = function(){
      for(var i =0; i<li.length; i++){
        li[i].className="";
        odiv[i].className = "off";
      }
      this.className ="on";
      odiv[this.index].className = "block";
    }
  }

</script>

</html>

firefox_2018-04-02_17-01-46.png

客服问答

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>自动应答</title>
  <style>
  .box{
    margin: 30px auto;
    padding: 10px;
    width: 200px;
    height: 300px;
    border: 1px solid #ccc;
  }
  #nr{
    margin-bottom: 10px;
    width: 100%;
    height: 250px;
    border-bottom: 1px solid #ccc;
    overflow: auto;
  }
  input, button{
    outline: 0;
  }
  input{
    width: 70%;
  }
  button{
    width: 25%;
  }
  ul,li{
    padding: 0;
    list-style: none;
  }
  

  </style>
</head>
<body>
  <div class="box">
    <div id="nr">
    </div>
    <input id="iput" type="text">
    <button id="btn">发送</button>
  </div>
</body>
<script>
  var neir = document.querySelector("#nr");
  var input = document.querySelector("#iput");
  var btn = document.querySelector("#btn");

  var list = ["小明","王五","张四","大刘"];

  btn.onclick = function(){
    var inneirong = input.value;
    // 创建一个ul,li节点,
    var ul = document.createElement("ul");
    var li = document.createElement("li");
    // innerHTML支持字符串拼接,及html标签(需放在引号内"").
    li.innerHTML = "你:"+ inneirong;
    if(inneirong.length === 0){
      alert("请输入内容");
    }else{
      // 依次将创建的ul, li放入id=nr的div节点中.
      neir.appendChild(ul.appendChild(li));
      // setTimeout:用于在指定的毫米数后调用函数或计算表达式
      setTimeout(function(){
          var info = ["小明","王五","张四","大刘"   ];
          var temp = info[Math.floor(Math.random()*4  )];
          var reply = document.createElement('li');
          reply.innerHTML = "客服:" + temp;
          neir.appendChild(ul.appendChild(reply));
      },200)
    }
}
// 讲input输入框清空 
  input.value = "";
</script>
</html>

2018-04-02_17-00-10.png

2018-04-02_17-19-19.png

2018-04-02_17-19-29.png

今日重点:

选项卡:

    选项卡标签栏li的border-top添加一个2px的透明边,这样在选中时就不会额外添加2px的红色边框,对布局造成影响.

    通过js修改标签class的属性,使用className="";

    鼠标时间onmouseover;当鼠标移入时,执行函数中的语句;

    for循环;要设置结束条件,否则会死循环.

客服应答:

    创建节点:createElement("li");

    添加创建的节点:ul.appendChild(li);

    innerHTML,可以加入html标签(用""包起来),字符串拼接;

    Math.floor(Mah.random()*4)返回0~3的随机数.注意不包括4:

    setTimeout(function(){},200);在200ms以后执行函数


本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学