当前位置: 首页 > news >正文

BOM与DOM

一,BOM(Browser Object Model浏览器对象模型)

1.history对象

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>页面1</title>
</head>
<body><a href="page02.html">去下一个页面</a>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>页面2</title>
</head>
<body><a href="javascript:history.back()">返回上一个页面</a><a href="javascript:history.forward()">去下一个页面1</a><a href="page03.html">去下一个页面2</a>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>页面3</title>
</head>
<body><a href="javascript:history.go(-2)">返回第一个页面</a><a href="javascript:history.back()">返回上一个页面</a>
</body>
</html>

2.location对象

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>location对象</title>
</head>
<body><a href="javascript:void(0)" onclick="showAdgress()">显示地址栏信息</a><a href="javascript:void(0)" onclick="refresh()">刷新页面</a><a href="javascript:void(0)" onclick="changepage()">替换新页面</a>
</body><script type="text/javascript">function showAdgress(){console.log(location.host)console.log(location.hostname)console.log(location.href)}function refresh(){location.reload();}function changepage(){location.replace("page01.html")}</script>
</html>

3.document对象

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>document对象</title>
</head>
<body><div id="a" >a</div><div id="b" class="c">b</div><div class="c">c</div><div name="d">d</div>
</body><script type="text/javascript">let div=document.getElementById("a");console.log(div);console.log("=================");let divarr=document.getElementsByTagName("div");console.log(divarr);console.log("=================");let arr=document.getElementsByClassName("c");console.log(arr);console.log("=================");let namearr=document.getElementsByName("d");console.log(namearr)console.log("=================");</script>
</html>

4.date对象

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>日期类</title>
</head>
<body></body>
<script type="text/javascript">let now=new Date();let year=now.getFullYear();let month=now.getMonth()+1;let date=now.getDate();let hour=now.getHours();let minute=now.getMinutes();let second=now.getSeconds();let time=year+"-"+fillzero(month,2)+"-"+fillzero(date,2)+" "+fillzero(hour,2)+":"+fillzero(minute,2)+":"+fillzero(second,2);console.log(time);function fillzero(num,targetlen){let str=num+"";if(str.length<targetlen){str="0"+str;}return str;}
</script>
</html>

5.周期函数和延迟函数

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>周期函数和延迟函数</title>
</head>
<body>
<div id="time"></div>
</body>
<script type="text/javascript">function fillzero(num,targetlen){let str=num+"";if(str.length<targetlen){str="0"+str;}return str;}//写法1/*setInterval(function(){let now=new Date();let year=now.getFullYear();let month=now.getMonth()+1;let date=now.getDate();let hour=now.getHours();let minute=now.getMinutes();let second=now.getSeconds();let time=year+"-"+fillzero(month,2)+"-"+fillzero(date,2)+" "+fillzero(hour,2)+":"+fillzero(minute,2)+":"+fillzero(second,2);let div=document.getElementById("time");div.textContent=time;},1000);*///写法2let count=0;function showtime(){let now=new Date();let year=now.getFullYear();let month=now.getMonth()+1;let date=now.getDate();let hour=now.getHours();let minute=now.getMinutes();let second=now.getSeconds();let time=year+"-"+fillzero(month,2)+"-"+fillzero(date,2)+" "+fillzero(hour,2)+":"+fillzero(minute,2)+":"+fillzero(second,2);let div=document.getElementById("time");div.textContent=time;/*count++;if(count===3){clearInterval(T);}*/}//setInterval(showtime,1000);//写法3/*let T=setInterval('showtime()',1000)*/let ti=setTimeout(showtime,3000);//延迟执行函数clearTimeout(ti);
</script>
</html>

二,DOM(Document Object Model文档对象模型)

1.节点和元素

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>节点</title>
</head>
<body><div id="box"><div><input type="text"></div><a href="javascript:void(0)">超链接1</a><a href="javascript:void(0)">超链接2</a><a href="javascript:void(0)">超链接3</a><a href="javascript:void(0)">超链接4</a><a href="javascript:void(0)">超链接5</a></div><a href="javascript:void(0)">超链接5</a>
</body>
<script type="text/javascript">let box=document.getElementById("box")/*//节点:enter键、注释都算节点console.log(box.parentNode);console.log(box.childNodes);console.log(box.firstChild);console.log(box.lastChild)console.log(box.firstChild.nextSibling);console.log(box.lastChild.previousSibling)*///元素console.log(box.parentElement);let child=box.children;console.log(child)console.log(box.firstElementChild.nextElementSibling)console.log(box.lastElementChild.previousElementSibling)</script>
</html>

http://www.dtcms.com/a/416054.html

相关文章:

  • 广东外贸网站推广公司wordpress去除下一页
  • 网站运营与网络推广方案二手房网站开发
  • 莞城区做网站山西网站建设服务
  • 做外贸有哪些好的网站有哪些湘潭做网站 用户多磐石网络
  • 数据结构与算法7:树和二叉树
  • 婚纱网站模板下载建电影网站程序
  • 医疗设备响应式网站临沂网站推广排名
  • Lazarus结合Lazserial多线程方式的串口采集实操心得
  • nano工具
  • 专门做西装网站wordpress alipay
  • 网络公司企业网站源码aso优化违法吗
  • 中国建设法律法规网官方网站手机可以搭建网站吗
  • 怎么用网站做文案wordpress网站有支付功能吗
  • 手工做皮具国外的网站工信部网站报备
  • 上海高端品牌网站建设专家郑州东区做网站电话
  • 手表网站起名网站常用插件
  • 网站建设推广接单语wordpress 3.5 漏洞
  • 保定模板做网站手机在线做ppt的网站有哪些问题
  • win8扁平化网站牙科医院网站源码
  • 徐州建设局网新网站永康电子商务网站建设公司
  • 加盟网站建设公司电子商务网站帮助中心该怎么更好地设计
  • OpenDDS运行配置可编程化
  • 河南郑州网站制作wordpress博客页面显示文章在哪
  • 献县做网站的深圳市罗湖区住房和建设局官网
  • 郑州做网站的公司有哪些net域名大网站
  • 三相变流器矢量控制及参数设计系列(1):引言
  • 石家庄设计网站公司WordPress文章分栏置顶
  • 网站建设叁金手指花总6大学生做家教网站
  • 一流的盐城网站建设jsp网站建设项目实战总结
  • 波动率建模(二)GARCH模型及Python实现