作业一:两个列表之间数据从一个列表移动到另一个列表

<div style="width:600px; height:500px; margin-top:20px">
  <div style="width:200px; height:300px; float:left">
    <select id="list1" size="10" style="width:200px; height:300px">
      <option>山东</option>
      <option>北京</option>
      <option>河北</option>
      <option>黑龙江</option>
      <option>河南</option>
    </select>
  </div>
  <div style="width:80px; height:300px; float:left">
    <input type="button" value="单移" id="btn1" style="width:70px; height:30px" onclick="Dan()"/>
    <input type="button" value="全移" id="btn2" style="width:70px; height:30px" onclick="Duo()"/>
  </div>
  <div style="width:200px; height:300px; float:left">
    <select id="list2" size="10" style="width:200px; height:300px"></select>
  </div>
</div> function Dan()
{
  var list1 = document.getElementById("list1"); //把列表1选中值取出
  var v = list1.value;
  var s = "<option class='o2'>"+v+"</option>"; //造一个option项
  var attr = document.getElementsByClassName("o2"); //把造的option项放在一个数组里面。
  var cz = true;//默认是true
  for(var i=0;i<attr.length;i++)
  {
    if(attr[i].innerHTML==v) //判断右侧列表里是否有重复的
    {
      cz = false;
      break;
    }
  }   if(cz)
  {
    var list2 = document.getElementById("list2"); // 将option项扔到list2
    list2.innerHTML +=s;//在列表2添加上
  }
}
function Duo()
{
  document.getElementById("list2").innerHTML = document.getElementById("list1").innerHTML; 直接复制列表选项
}

作业二:日期时间选择

<div style="width:600px; height:100px;">
  <select id="year"></select>年
  <select id="month" onchange="FillDay()"></select>月
  <select id="day"></select>日
</div>
</body>
<script type="text/javascript">
FillYear();
FillMonth();
FillDay();
function FillYear()
{
  var sj = new Date();//现在的日期时间
  var nian = sj.getFullYear();//获取年份
  var s = "";
  for(var i=nian-5;i<nian+6;i++)//上下都是5年,i里面存的是年
  {
    if(i==nian)//如果i等于当前的年,也就是2016年。
    {
      s +="<option selected='selected'>"+i+"</option>";//下拉列表中默认出现的年份
    }
    else
    {
      s +="<option>"+i+"</option>";//普通的年份
    }
  }   document.getElementById("year").innerHTML = s;//把这个字符串给年份的下拉
}
function FillMonth()
{
  var sj = new Date();//在这个位置调用
  var yue = sj.getMonth()+1;
  var s = "";
  for(var i=1;i<13;i++)
  {
    if(i==yue)
    {
      s +="<option selected='selected'>"+i+"</option>";
    }
    else
    {
      s +="<option>"+i+"</option>";
    }
  }
  document.getElementById("month").innerHTML=s;
}
function FillDay()
{
  var sj = new Date();
  var tian = sj.getDate();
  var yue = document.getElementById("month").value; 取月份求天数
  var n = 31;
  if(yue==4 || yue==6 ||yue==9 ||yue==11)
  {
    n = 30;
  }
  else if(yue==2)
  {
    n=28;
  }
  var s = ""; 用循环添加
  for(var i=1;i<n+1;i++)
  {
    if(i==tian)
    {
      s +="<option selected='selected'>"+i+"</option>";
    }
    else
    {
      s +="<option>"+i+"</option>";
    }
  }
  document.getElementById("day").innerHTML = s;
}

例题一、子菜单下拉

<style type="text/css">
*{ margin:0px auto; padding:0px}
#menu{ width:700px; height:40px; border:1px solid #999; margin-top:30px}
.list{ width:100px; height:40px; text-align:center; line-height:40px; vertical-align:middle; font-size:16px; font-family:微软雅黑; float:left}
.list:hover{ cursor:pointer; background-color:#63C; color:white}
.ziwai{width:0px; height:0px;position:relative; float:left; top:40px; left:-100px}
.zi{ width:100px; height:100px; background-color:#6C3; display:none }//默认下拉都隐藏
</style>
</head>
<body>
<div id="menu">
  <div class='list' onmouseover="Show('z1')" onmouseout="YinCang()">首页</div>
    <div class="ziwai" >
      <div class="zi" id="z1"></div>
    </div>
  <div class='list' onmouseover="Show('z2')" onmouseout="YinCang()">产品介绍</div>
    <div class="ziwai" >
      <div class="zi" id="z2"></div>
    </div>
  <div class='list' onmouseover="Show('z3')" onmouseout="YinCang()">公司简介</div>
    <div class="ziwai" >
      <div class="zi" id="z3"></div>
    </div>
  <div class='list' onmouseover="Show('z4')" onmouseout="YinCang()">联系我们</div>
    <div class="ziwai" >
      <div class="zi" id="z4"></div>
    </div>
  <div class='list' onmouseover="Show('z5')" onmouseout="YinCang()">新闻动态</div>
    <div class="ziwai" >
      <div class="zi" id="z5"></div>
    </div>
</div>
</body>
<script type="text/javascript">
function Show(id)
{
  var attr = document.getElementsByClassName("zi");   for(var i=0; i<attr.length;i++)
  {
    attr[i].style.display = "none"; 让所有的子菜单隐藏
  }
  document.getElementById(id).style.display = "block"; 让和该菜单关联的子菜单显示
}
function YinCang()
{
  var attr = document.getElementsByClassName("zi");
  for(var i=0; i<attr.length;i++)
  {
    attr[i].style.display = "none";
  }
}
</script>

例题二、用div做下拉列表

<title>无标题文档</title>
<style type="text/css">
*{ margin:0px auto; padding:0px}
#xiala{ width:180px; height:33px; border:1px solid #999;text-align:center; line-height:33px; vertical-align:middle; }
#xiala:hover{ cursor:pointer} #zi{width:180px; height:150px; border:1px solid #63C; border-top:0px; display:none} .list{width:180px; height:33px; text-align:center; line-height:33px; vertical-align:middle; border-bottom:1px solid #63C; background-color:#CCC}
.list:hover{ cursor:pointer; background-color:#63C; color:white} </style> </head> <body> <div style="width:700px; height:500px; margin-top:30px">   <div id="xiala" onclick="Show()"></div>
  <div id="zi">
    <div class="list" onclick="Xuan(this)">山东</div>//this表示一个元素这个元素相当于它本身。this写在哪一行里,就相当于这一行本身。
    <div class="list" onclick="Xuan(this)">淄博</div>
    <div class="list" onclick="Xuan(this)">张店</div>
  </div>
</div> </body>
<script type="text/javascript">
function Show()
{
  document.getElementById("zi").style.display="block";
}
function Xuan(ys)//ys代表选中的元素(山东、淄博、张店所在的div)
{
  var v = ys.innerText;
  document.getElementById("xiala").innerText = v;
  document.getElementById("zi").style.display="none";
}
</script>

事件总结

通用:

1.onclick      鼠标单击效果

2.ondbclick  鼠标双击效果

3.onchange 表单的值改变

4.onmouseover  鼠标放上

5.onmouseout   鼠标离开

6.onmousemove  鼠标移动

表单特有:

1.onchang 表单的值改变
2.onblur 失去焦点
3.onfocus 获得焦点
4.onselect 选中

JS之document例题讲解1(两张表之间数据转移、日期时间选择、子菜单下拉、用div做下拉菜单、事件总结)的更多相关文章

  1. 关于跨DB增量(增、改)同步两张表的数据小技巧

    有些场景下,需要隔离不同的DB,彼此DB之间不能互相访问,但实际的业务场景又需要从A DB访问B DB的情形,这时怎么办?我认为有如下常规的三种方案: 1.双方提供RESET API,需要访问不同DB ...

  2. EF Core中如何正确地设置两张表之间的关联关系

    数据库 假设现在我们在SQL Server数据库中有下面两张表: Person表,代表的是一个人: CREATE TABLE [dbo].[Person]( ,) NOT NULL, ) NULL, ...

  3. django同时查询两张表的数据,合并检索对象返回

    原始需求: 1.一篇文章内容分N个版块,每篇文章的版块数量不同. 2.有个文章搜索功能,需要同时搜索标题和内容. 实现思路: 1.由于每篇文章的内容版块数量不同,因此将每个文章的标题和内容分开存入2张 ...

  4. 一起学Hadoop——实现两张表之间的连接操作

    ---恢复内容开始--- 之前我们都是学习使用MapReduce处理一张表的数据(一个文件可视为一张表,hive和关系型数据库Mysql.Oracle等都是将数据存储在文件中).但是我们经常会遇到处理 ...

  5. mysql 如何找出两张表之间的关系

    分析步骤: #1.先站在左表的角度去找 是否左表的多条记录可以对应右表的一条记录,如果是,则证明左表的一个字段foreign key 右表一个字段(通常是id) #2.再站在右表的角度去找 是否右表的 ...

  6. 【第十五篇】easyui datagrid的列编辑,同时插入两张表的数据进去

    看图说话. 需求:插入两张表,上面的表单是第一张表的内容,下面的两个表格是第二张详情表的内容,跟第一张表的id关联 第二张表有一个列是需要用户手动填写添加的. 国际惯例,上代码 <div id= ...

  7. 利用pymysql同时修改两张表的数据

    使用pymysql操作数据库中相关联的两张表需求:两张表中分别有一个字段是json格式,需要往json中再插入一个属性值’container_cloud’=’fasle’. import pymysq ...

  8. Oracle将两张表的数据插入第三张表且第三张表中不存在

    1.由于是先查再插所以不能使用insert into table1() values(), 要使用insert into table1() select * table2,不能使用values. 2. ...

  9. JS之document例题讲解2

    例题三.图片轮播 <body> <div style="width:1000px; height:250px; margin-top:30px"> < ...

随机推荐

  1. Debian常用設置

    1. 更新軟件源 sudo cp /etc/apt/sources.list /etc/apt/sources.list_bak #備份 sudo vi /etc/apt/sources.list / ...

  2. <Effective C++>读书摘要--Ctors、Dtors and Assignment Operators<二>

    <Item 9> Never call virtual functions during construction or destruction 1.you shouldn't call ...

  3. django使用ajax提交表单数据报403错解决方法

    只需要在.ajaxSetup方法中设置csrfmiddlewaretoken即可 $.ajaxSetup({ data: {csrfmiddlewaretoken: '{{ csrf_token }} ...

  4. [剑指Offer] 51.构建乘积数组

    题目描述 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1].不 ...

  5. HttpServletRequestWrapper 是HttpServletRequest的包装类 ·关系相当于 int 与integer的关系

    HttpServletRequestWrapper 是HttpServletRequest的包装类 ·关系相当于 int 与integer的关系

  6. 【bzoj1707】[Usaco2007 Nov]tanning分配防晒霜 贪心+Treap

    题目描述 奶牛们计划着去海滩上享受日光浴.为了避免皮肤被阳光灼伤,所有C(1 <= C <= 2500)头奶牛必须在出门之前在身上抹防晒霜.第i头奶牛适合的最小和最 大的SPF值分别为mi ...

  7. 具体数学数论章-----致敬Kunth

    整除性(divisible): 引入了代表整除性. m\n (m|n) 表示m整除n.注意这里的整除.表示的是n = km(k为整数). 在整除性这里.m必须是个正数.也许你可以描述n 是 m 的k倍 ...

  8. [CF1083C]Max Mex

    题目大意:有一棵$n(n\leqslant2\times10^5)$个点的树,每个点有点权,所有的点权构成了$0\sim n-1$的排列.$q(q\leqslant2\times10^5)$次操作,操 ...

  9. BZOJ4596:[SHOI2016]黑暗前的幻想乡——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=4596 https://www.luogu.org/problemnew/show/P4336#su ...

  10. BZOJ [Ctsc2002] Award 颁奖典礼 解题报告

    [Ctsc2002] Award 颁奖典礼 Description IOI2002的颁奖典礼将在YONG-IN Hall隆重举行.人们在经历了充满梦幻的世界杯之后变得更加富于情趣.为了使颁奖典礼更具魅 ...