Upload 810 files
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- .gitattributes+4
- BOM/.DS_StoreAdded
- BOM/01_BOM概述.htmlAdded+22
- BOM/02_script工作原理.htmlAdded+18
- BOM/03_回流和重绘.htmlAdded+43
- BOM/04_定时器1_setTimeout.htmlAdded+66
- BOM/04_定时器2_setInterval.htmlAdded+55
- BOM/04_定时器3_实操.htmlAdded+34
- BOM/04_定时器4_防抖debounce.htmlAdded+82
- BOM/04_定时器5_节流throttle.htmlAdded+56
- BOM/05_window对象1_属性.htmlAdded+49
- BOM/05_window对象2_方法.htmlAdded+31
- BOM/06_Navigator对象.htmlAdded+32
- BOM/07_Screen对象.htmlAdded+28
- BOM/08_History对象1.htmlAdded+25
- BOM/08_History对象2.htmlAdded+24
- BOM/09_封装cookie.htmlAdded+53
- BOM/10_apply_call_bind函数.htmlAdded+90
- BOM/css/tab.cssAdded+60
- BOM/js/hello.jsAdded+1
- BOM/js/index01.jsAdded+1
- BOM/js/index02.jsAdded+3
- BOM/js/tab.jsAdded+31
- DOM/01_DOM概述.htmlAdded+26
- DOM/02_document对象_属性.htmlAdded+46
- DOM/03_document对象_方法1_获取元素.htmlAdded+56
- DOM/03_document对象_方法2_创建元素.htmlAdded+45
- DOM/04_Element对象_属性.htmlAdded+37
- DOM/05_Element对象_有关位置的属性1.htmlAdded+56
- DOM/05_Element对象_有关位置的属性2.htmlAdded+35
- DOM/05_Element对象_有关位置的属性3.htmlAdded+34
- DOM/05_Element对象_有关位置的属性4.htmlAdded+47
- DOM/06_Element对象_方法.htmlAdded+44
- DOM/07_Attribute属性.htmlAdded+35
- DOM/08_Text节点.htmlAdded+34
- DOM/09_DocumentFragment节点.htmlAdded+33
- DOM/10_Node节点属性1_nodeName.htmlAdded+28
- DOM/10_Node节点属性2_nodeValue.htmlAdded+23
- DOM/10_Node节点属性3_textContent.htmlAdded+25
- DOM/10_Node节点属性4_nextSibling.htmlAdded+35
- DOM/10_Node节点属性5_previousSibling.htmlAdded+25
- DOM/10_Node节点属性6_parentNode.htmlAdded+29
- DOM/10_Node节点属性7_firstChild_lastChild.htmlAdded+35
- DOM/10_Node节点属性8_childNodes.htmlAdded+36
- DOM/11_Node节点方法1_appendChild.htmlAdded+41
- DOM/11_Node节点方法2_hasChildNodes.htmlAdded+41
- DOM/11_Node节点方法3_cloneNode.htmlAdded+29
- DOM/11_Node节点方法4_insertBefore.htmlAdded+36
- DOM/11_Node节点方法5_removeChild.htmlAdded+51
- DOM/11_Node节点方法6_replaceChild.htmlAdded+33
37 unmodified lines38394037 unmodified lines03_JavaScript基本语法.ipynb filter=lfs diff=lfs merge=lfs -text04_DOM模型.ipynb filter=lfs diff=lfs merge=lfs -text08_jQuery.ipynb filter=lfs diff=lfs merge=lfs -text37 unmodified lines3839404142434437 unmodified lines03_JavaScript基本语法.ipynb filter=lfs diff=lfs merge=lfs -text04_DOM模型.ipynb filter=lfs diff=lfs merge=lfs -text08_jQuery.ipynb filter=lfs diff=lfs merge=lfs -textcss/47_小米官网项目/13.小米官网项目.pdf filter=lfs diff=lfs merge=lfs -textcss/48_响应式项目/14.响应式项目.pdf filter=lfs diff=lfs merge=lfs -texthtml/18_HTML5新增元素/data/games.mp4 filter=lfs diff=lfs merge=lfs -texthtml/18_HTML5新增元素/data/returns.mp3 filter=lfs diff=lfs merge=lfs -text
12345678910111213141516171819202122<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<!-- <script>
console.log("Hello");
</script> -->
<!-- <script src="./js/index01.js"></script> -->
<script src="//unpkg.com/swiper/swiper-bundle.min.js"></script> </body></html>123456789101112131415161718<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <!-- <script src="./js/index.js" defer></script> --> <script src="./js/hello.js" async></script> <script src="./js/index02.js" async></script> </head><body>
<div id="box">盒子</div> </body></html>12345678910111213141516171819202122232425262728293031323334353637383940414243<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style>
#box{ width: 100px; height: 100px; background-color: red; }
#box.current-box{ background-color: green; width: 200px; }
</style></head><body>
<div id="box"></div> <button id="btn">按钮</button> <script>
var btn = document.getElementById("btn"); var box = document.getElementById("box");
btn.onclick = function(){ // box.style.width = "200px" // 回流:开支更高 // box.style.background = "green"; // 重绘:开支相对比低一些 box.className = "current-box" }
</script>
</body></html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566<!DOCTYPE html><html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head>
<body>
<script>
// var timer = setTimeout(function(){ // console.log("hello"); // },5000)
// // this在不被改变的情况下,在定时器中指向window
// var username = "sxt"; // var user = { // username:"itbaizhan", // getName:function(){ // setTimeout(function(){ // // this指向window // console.log(this.username); // },1000) // } // }
// user.getName(); // sxt
// function logHello(){ // console.log("hello"); // } // var timer = setTimeout(logHello,3000)
// var username = "sxt"; // var user = { // username: "itbaizhan", // getName: function () { // var that = this; // setTimeout(function () { // // this指向window // console.log(that.username); // }, 1000) // } // }
// user.getName(); // itbaizhan
// var timer = setTimeout(function(){ // console.log("hello"); // },3000)
// clearTimeout(timer);
</script>
</body>
</html>12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455<!DOCTYPE html><html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> #box { width: 100px; height: 100px; background: red; } </style></head>
<body>
<div id="box"></div>
<script>
setInterval(function () { console.log("hello"); }, 1000)
</script>
<script>
var box = document.getElementById('box'); var opacity = 1; var timer = setInterval(function () { opacity -= 0.05; if (opacity <= 0) { // 清除定时器 clearInterval(timer) } else { box.style.opacity = opacity } }, 30)
setInterval(function () { console.log(new Date().toLocaleTimeString()); }, 1000)
</script>
</body>
</html>12345678910111213141516171819202122232425262728293031323334<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="./css/tab.css"></head><body>
<div class="container"> <div class="up"> <ul> <li class="select"><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="down"> <div class="div-select">百度内容</div> <div>新浪内容</div> <div>淘宝内容</div> <div>京东内容</div> <div>网易内容</div> </div> </div>
<script src="./js/tab.js"></script>
</body></html>12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182<!DOCTYPE html><html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box { height: 300px; } </style></head>
<body>
<div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div>
<script>
// var timer = null; // function debounce() { // if (timer) { // clearTimeout(timer) // } // timer = setTimeout(function () { // var scollTop = document.documentElement.scrollTop; // console.log(scollTop); // },300) // }
// window.onscroll = function () { // debounce(); // }
/** * 1. 定时器 * 2. 闭包 * 3. 事件机制 * 事件在注册的时候,只执行一次,后续的不间断的触发事件,是在执行事件里面的内容 * 不是在一直触发事件函数 */
function debounce(fn, delay) { var timer = null; // 局部作用域,不污染全局命名空间 return function () { if (timer) { clearTimeout(timer) } timer = setTimeout(fn, delay) } }
function backTop() { var scollTop = document.documentElement.scrollTop; console.log(scollTop); }
window.onscroll = debounce(backTop, 300)
// window.onscroll = function () { // var result = debounce(backTop, 300); // result(); // }
// // 只有第一次注册的时候执行一次,不间断执行的是里面的函数体 // div.onclick = function(){ // console.log("111"); // }
</script>
</body>
</html>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556<!DOCTYPE html><html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box { height: 300px; } </style></head>
<body>
<div class="box">内哦给你</div> <div class="box">内哦给你</div> <div class="box">内哦给你</div> <div class="box">内哦给你</div> <div class="box">内哦给你</div> <div class="box">内哦给你</div>
<script>
function throttle(fn, delay) { var valid = true;
return function () { if(!valid){ // 暂不接客 return false; // 后面的代码不在执行 } valid = false; setTimeout(function () { fn(); valid = true; },delay) } }
function backTop() { var scollHeight = document.documentElement.scrollTop; console.log(scollHeight); }
window.onscroll = throttle(backTop,1000);
</script>
</body>
</html>12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style>
.box{ height: 300px; }
</style></head><body>
<div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div>
<script>
(function(){ var username = "itbaizhan"; })();
console.log(window);
console.log(window.screenX); console.log(window.screenY);
console.log(window.innerHeight); console.log(window.innerWidth);
console.log(window.outerHeight); console.log(window.outerWidth);
console.log(window.scrollX); console.log(window.scrollY);
</script> </body></html>12345678910111213141516171819202122232425262728293031<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<script>
alert("我是对话框");
var result = prompt("您的年龄",19); console.log(result);
var ok = confirm("最近还好么?"); if(ok){ console.log("挺好的,但不如我好"); }else{ console.log("过的不好"); }
window.open("https://itbaizhan.com")
</script> </body></html>1234567891011121314151617181920212223242526272829303132<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<script>
var ua = navigator.userAgent.toLocaleLowerCase(); if(ua.indexOf("mobi") > -1){ console.log("手机浏览器"); }else{ console.log("电脑浏览器"); }
for(var i = 0;i<navigator.plugins.length;i++){ console.log(navigator.plugins[i].name); console.log(navigator.plugins[i].description); }
console.log(navigator.platform); console.log(navigator.language); console.log(navigator.languages);
</script> </body></html>12345678910111213141516171819202122232425262728<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<script>
console.log(window.screen); // 1920 * 1080 console.log(window.screen.height); console.log(window.screen.width); console.log(window.screen.availHeight); console.log(window.screen.availWidth);
console.log(window.screen.pixelDepth); console.log(window.screen.orientation.type);
</script> </body></html>12345678910111213141516171819202122232425<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<h3>Hello</h3> <button id="btn">回退</button>
<script>
var btn = document.getElementById("btn"); btn.onclick = function(){ // history.back(); history.go(-1) }
</script> </body></html>123456789101112131415161718192021222324<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body> <a href="./hello.html">百战</a> <button id="btn">前进</button> <script>
var btn = document.getElementById("btn"); btn.onclick = function(){ // history.forward(); history.go(1) }
</script>
</body></html>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<h3>学习Cookie</h3>
<script>
/* 1. 设置 2. 获取 3. 删除 */
var cookie = { // name value 过期时间 set:function(name,value,days){ var d = new Date(); d.setDate(d.getDate() + days); // 设置过期时间 name=itbaizhan; document.cookie = name + "=" + value +";expires=" + d+";"; }, // 读取cookie,知道你要读取的是那个cookie get:function(name){ var cookiesArr = document.cookie.split("; ") for(var i = 0;i< cookiesArr.length;i++){ var newArr = cookiesArr[i].split("="); if(name === newArr[0]){ return newArr[1] } } }, // 干掉哪一个cookie unset:function(name){ this.set(name,"",-1) } }
// cookie.set("sxt","iwen",30); // console.log(cookie.get("name"));; cookie.unset("name");
</script> </body></html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990<!DOCTYPE html><html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head>
<body>
<script>
/* 回顾this指向 1. 事件中的this,指向当前DOM元素 2. 对象中的this,指向当前调用者 3. 闭包中的this,指向window 4. 定时器中的this,指向window 5. call、apply和bind改变this指向 */
// var user = { // name:"itbaizhan", // getName:function(){ // console.log(this.name); // } // }
// var username = "sxt" // function getFn(){ // var username = "itbaizhan" // return function(){ // console.log(this.username); // } // }
// var name = "sxt" // var user = { // name:"itbaizhan", // getName:function(){ // setTimeout(function(){ // console.log(this.name); // }) // } // }
// user.getName() </script>
<script>
var user = { name: "itbaizhan", getName: function (city) { console.log(this.name,city); } }
var people = { name: "sxt" }
// user.getName(); // 指向user // this指向,传递的额外参数 // user.getName.call(people); // sxt // user.getName.apply(people); // sxt // user.getName.bind(people)(); // sxt // 由此得出结论,bind 返回的是一个新的函数,你必须调用它才会被执行
// call和apply的区别 // call和apply接受的参数是不同的 // user.getName.call(people,"北京"); // sxt 北京 // user.getName.apply(people, ["北京"]); // sxt 北京
var arr = [10,20,30]; console.log(Math.max.apply(window,arr)); // null === window
console.log(Math.max.call(window,10,20,30)); console.log(Math.max(10,20,30));
</script>
</body>
</html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960*{ margin: 0; padding: 0;}
body{ background-color: gray;}
.container{ width: 300px; height: 200px; background-color: #fff; margin: 100px auto;}
.container .up{ height: 50px; width: 100%;}
.container .up ul{ list-style-type: none; text-align: center;}
.container .up ul li{ float: left; width: 60px; height: 50px; line-height: 50px;}
.container .up ul li a{ text-decoration: none; font-size: 20px;}
.select{ border-bottom: 2px solid orange;}
.container .down{ height: 100px; width: 100%; position: relative; text-align: center;}
.container .down div{ position:absolute; line-height: 100px; height: 100%; width: 100%; display: none;}
.container .down div.div-select{ display: block;}1var hello = "hello"1console.log("hello");123var box = document.getElementById("box");console.log(box);console.log(hello);12345678910111213141516171819202122232425262728293031// 1. 获取到页面所有的元素var lis = document.querySelector(".up").querySelectorAll("li");var divs = document.querySelector(".down").querySelectorAll("div");var timer = null;var delay = 300;
// 闭包帮我们保存变量到内存中for (var i = 0; i < lis.length; i++) { (function (i) { lis[i].onmouseenter = function () { timer = setTimeout(function () { for (var j = 0; j < lis.length; j++) { lis[j].removeAttribute("class"); divs[j].removeAttribute("class") } lis[i].setAttribute("class", "select") divs[i].setAttribute("class", "div-select") },delay) } }(i)) lis[i].onmouseleave = function(){ clearTimeout(timer) }}/** * 1. 获取元素 * 2. 闭包 * 3. 事件:鼠标滑动事件 * 4. 属性的操作:添加、删除 */1234567891011121314151617181920212223242526<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<!-- 注释 -->
<div> <p class="ptext">文档</p> </div>
<script>
console.log(document); console.log(document.nodeType); // 9 console.log(Node.DOCUMENT_NODE);
</script>
</body></html>12345678910111213141516171819202122232425262728293031323334353637383940414243444546<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<form></form> <form></form> <form></form>
<img src="./images/banner.png" alt=""> <img src="./images/girl.png" alt="">
<script src="./js/index.js"></script> <script>
// console.log(document.doctype); // console.log(document.documentElement); // 根节点:html // console.log(document.head); // console.log(document.body);
// console.log(document.forms);
// console.log(document.images);
// var images = document.images; // for(var i = 0;i<images.length;i++){ // if(images[i].src === "file:///E:/itbaizhan/WEBCode/02.%E7%AC%AC%E4%BA%8C%E9%98%B6%E6%AE%B5%EF%BC%9AJavaScript/6.%E7%AC%AC%E5%85%AD%E7%AB%A0%EF%BC%9ADOM%E6%A8%A1%E5%9E%8B/02_document%E5%AF%B9%E8%B1%A1_%E5%B1%9E%E6%80%A7/images/banner.png"){ // console.log("页面存在banner"); // } // }
// console.log(document.scripts); console.log(document.domain);
</script>
</body></html>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div class="box1 box">box1</div> <div class="box2 box">box2</div> <div class="box3 box">box3</div>
<div name="container"></div> <div name="container"></div> <p name="container"></p>
<div id="root"></div>
<script>
// var divs = document.getElementsByTagName("div"); // // 给元素设置内容:innerHTML // console.log(divs[1]); // divs[1].innerHTML = "new box2"
// var allElements = document.getElementsByTagName('*'); // console.log(allElements);
// 使用率及广泛 // var divs = document.getElementsByClassName("box"); // console.log(divs); // divs[0].innerHTML = "new box1"
// var divs = document.getElementsByName("container"); // console.log(divs);
// var root = document.getElementById("root") // console.log(root); // 单一的元素,不再是集合 // root.innerHTML = "根元素"
// var box = document.querySelector(".box"); // css选择器 // console.log(box);
// var box = document.querySelectorAll(".box"); // css选择器 // console.log(box);
// var root = document.querySelector("#root"); // css选择器 // console.log(root);
</script> </body></html>123456789101112131415161718192021222324252627282930313233343536373839404142434445<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style>
.container{ color:red; }
</style></head><body>
<script>
var body = document.getElementsByTagName("body"); // 集合
var div = document.createElement("div"); var text = document.createTextNode("动态创建标签") var className = document.createAttribute("class");
className.value = "container"
div.appendChild(text); div.setAttributeNode(className);
// appendChild向父元素添加内容 body[0].appendChild(div);
var img = document.createElement("img"); // img.src = "images/girl.png" var imageSrc = document.createAttribute("src"); imageSrc.value = "images/girl.png"; img.setAttributeNode(imageSrc);
body[0].appendChild(img) </script> </body></html>12345678910111213141516171819202122232425262728293031323334353637<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="root" class="c1 container">容器</div>
<script>
var root = document.getElementById("root"); // console.log(root.id); // root // root.id = "container"; // console.log(root.id); // container
// console.log(root.className); // c1 // root.classList.add("active","error"); // root.classList.remove("error"); // console.log(root.classList.contains("containers"));; // root.classList.toggle("c1");
// console.log(root.innerHTML); // root.innerHTML = "<a href='http://itbaizhan.com'>百战程序员</a>";
// console.log(root.innerText); // root.innerText = "新的容器";
root.innerText = "<a href='http://itbaizhan.com'>百战程序员</a>";
</script> </body></html>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556<!DOCTYPE html><html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> * { padding: 0; margin: 0; }
.box { width: 100px; height: 100px; background: red; border: 20px solid yellow; padding: 10px; margin: 10px; } </style></head>
<body>
<div class="box" id="box"></div>
<script>
var box = document.getElementById("box");
// console.log(box.clientHeight); // console.log(box.clientWidth);
// 获取到视口的高度(可视区域,浏览器的窗口) // documentElement整个浏览器的可视窗口对象 // console.log(document.documentElement.clientHeight); // console.log(document.documentElement.clientWidth);
// // 网页的高度 // console.log(document.body.clientHeight); // console.log(document.body.clientWidth)
// console.log(box.clientLeft); // 10 // console.log(box.clientTop); // 10
// console.log(box.scrollHeight); // console.log(box.scrollWidth);
</script>
</body>
</html>1234567891011121314151617181920212223242526272829303132333435<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style>
.box{ height: 500px; width: 4000px; }
</style></head><body>
<div class="box">第一部分内容</div> <div class="box">第二部分内容</div> <div class="box">第三部分内容</div> <div class="box">第四部分内容</div>
<script> // 用户行为介入,咱们称他为事件 window.addEventListener("scroll",function(){ // console.log(document.documentElement.scrollTop);// 上下滚动 console.log(document.documentElement.scrollLeft);// 左右滚动 })
</script> </body></html>12345678910111213141516171819202122232425262728293031323334<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 100px; height: 100px; background: red; border: 10px solid yellow; padding: 10px; margin: 10px; }
</style></head><body>
<div class="box" id="box"></div> <script>
var box = document.getElementById("box"); console.log(box.offsetHeight); // 140 console.log(box.offsetWidth); // 140
</script> </body></html>1234567891011121314151617181920212223242526272829303132333435363738394041424344454647<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> /* *{ padding: 0; margin: 0; } */
.parent{ width: 200px; height: 200px; background: yellow; /* position: relative; */ }
.box{ width: 100px; height: 100px; background: red; position: relative; left: 50px; top: 50px; }
</style></head><body>
<div class="parent"> <div class="box" id="box"></div> </div> <script>
var box = document.getElementById("box"); console.log(box.offsetLeft); // 0 console.log(box.offsetTop); // 0
</script>
</body></html>1234567891011121314151617181920212223242526272829303132333435363738394041424344<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style>
.root{ width: 100px; height: 100px; background: red; position: relative; left: 100px; top: 100px; }
</style></head><body>
<input type="text" id="search">
<div id="box">我是子元素</div>
<div class="root" id="root"></div>
<script>
var search = document.getElementById("search"); search.focus(); // 获得焦点 search.blur(); // 失去焦点了
var box = document.getElementById("box"); box.remove();
var root = document.getElementById("root"); console.log(root.getBoundingClientRect().top);
</script> </body></html>1234567891011121314151617181920212223242526272829303132333435<!DOCTYPE html><html lang="en">
<head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head>
<body>
<a href="http://itbaizhan.com" data-itbaizhan="itbaizhan" id="it">百战程序员</a>
<script>
var it = document.getElementById("it"); // console.log(it.getAttribute("href")); // http://itbaizhan.com // console.log(it.setAttribute("title","百战程序员")); // console.log(it.hasAttribute("class")); // true // false // if(!it.hasAttribute("class")){ // it.setAttribute("class","itbaizhan") // }
// it.removeAttribute("title")
console.log(it.dataset.itbaizhan); // itbaizhan it.dataset.itbaizhan = "bjsxt"
</script>
</body>
</html>12345678910111213141516171819202122232425262728293031323334<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<p>Hello World</p> <script>
var p1 = document.querySelector("p").firstChild; // p.data = "Hello World!" // console.log(p.length); // 12 // p.appendData("!!!"); // appendChild -> Node
// p.deleteData(5,7); // Hello // p.insertData(6,"iwen "); // p.replaceData(6,6,"itbaizhan") // console.log(p.substringData(6,5));; // World // p.remove(); // 清空子节点,删除子节点
// var p2 = document.querySelector("p"); // console.log(p2.innerHTML = "");
</script>
</body></html>123456789101112131415161718192021222324252627282930313233<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<ul></ul>
<script>
var docFrag = document.createDocumentFragment();
var li = document.createElement("li"); li.innerHTML = "测试列表";
var li2 = document.createElement("li"); li2.innerHTML = "测试列表2"
docFrag.appendChild(li); docFrag.appendChild(li2);
var ul = document.querySelector("ul"); ul.appendChild(docFrag);
</script> </body></html>12345678910111213141516171819202122232425262728<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="box">盒子</div>
<script>
console.log(document.nodeName); // #document
var box = document.getElementById("box"); console.log(box.nodeName); // DIV console.log(box.getAttributeNode("id").nodeName); // id console.log(box.firstChild.nodeName); // #text
var docFrag = document.createDocumentFragment(); console.log(docFrag.nodeName); // #document-fragment
</script> </body></html>1234567891011121314151617181920212223<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="box">我是一个盒子</div>
<script>
var box = document.getElementById("box"); console.log(box.nodeValue); // null console.log(box.firstChild.nodeValue); // 我是一个盒子 box.firstChild.nodeValue = "欢迎来到百战程序员";
</script> </body></html>12345678910111213141516171819202122232425<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="box">WelCome:<span>iwen</span>,百战平台</div> <div id="root"></div> <script>
var box = document.querySelector("#box"); console.log(box.textContent); // WelCome:iwen,百战平台 console.log(box.innerHTML); // WelCome:<span>iwen</span>,百战平台
var root = document.querySelector("#root"); root.textContent = "新的数据";
</script> </body></html>1234567891011121314151617181920212223242526272829303132333435<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="box1">box1</div><div id="box2">box2</div>
<div id="root"> <p>内容1</p> <p>内容2</p> <p>内容3</p> </div>
<script>
// var box1 = document.getElementById("box1"); // console.log(box1.nextSibling); // <div id="box2">box2</div>
var rootP = document.getElementById("root").firstChild; while(rootP !== null){ if(rootP.nodeName !== "#text"){ console.log(rootP.nodeName); // P } rootP = rootP.nextSibling; }
</script> </body></html>12345678910111213141516171819202122232425<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="box1">box1</div><div id="box2">box2</div>
<script>
var box2 = document.getElementById("box2"); var box1 = document.getElementById("box1") console.log(box2.previousSibling); // <div id="box1">box1</div> console.log(box1); // <div id="box1">box1</div> console.log(box1 === box2.previousSibling); // true
</script> </body></html>1234567891011121314151617181920212223242526272829<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="parent"> <p id="content">我是内容</p> </div> <script>
var content = document.getElementById("content"); // console.log(content.parentNode);
// 自己删除自己的行为 if(content.parentNode){ content.parentNode.removeChild(content); }
</script>
</body></html>1234567891011121314151617181920212223242526272829303132333435<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="root"><p>内容1</p><p>内容2</p><p>内容3</p></div>
<p id="text"> <span>last span</span> </p>
<script>
var root = document.getElementById("root"); console.log(root.firstChild); // <p>内容1</p> console.log(root.lastChild); // <p>内容3</p> if(root.firstChild != null){ console.log("额外操作"); }else{ console.log("空的容器"); }
var text = document.getElementById("text"); console.log(text.lastChild.nodeName); </script> </body></html>123456789101112131415161718192021222324252627282930313233343536<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="root"> <ul> <li>列表1</li> <li>列表2</li> <li>列表3</li> </ul> <p>文本信息1</p> <p>文本信息2</p> </div>
<script>
var root = document.getElementById("root"); console.log(root.childNodes[3]); // 第一个p标签
for(var i = 0;i<root.childNodes.length;i++){ if(root.childNodes[i].nodeName === "P"){ console.log(root.childNodes[i]); // 所有的P标签 root.childNodes[i].innerHTML = "新的数据" + i } }
</script> </body></html>1234567891011121314151617181920212223242526272829303132333435363738394041<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div class="box"></div>
<p id="text">hello</p>
<ul id="list"></ul>
<script>
var box = document.querySelector(".box"); var text = document.getElementById("text");
box.appendChild(text);
var span = document.createElement("span"); span.innerHTML = "hello span"; text.appendChild(span);
var list = document.getElementById("list"); for(var i = 0;i<10;i++){ var li = document.createElement("li"); li.innerHTML = "列表" + (i+1); list.appendChild(li) }
</script> </body></html>1234567891011121314151617181920212223242526272829303132333435363738394041<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="root"> <p>Hello</p> <h3>标题</h3> </div>
<script>
var root = document.getElementById("root"); // console.log(root.hasChildNodes()); // if(root.hasChildNodes()){ // console.log("存在子元素"); // }else{ // console.log("不存在子元素"); // }
if(root.hasChildNodes()){ for(var i = 0;i<root.childNodes.length;i++){ if(root.childNodes[i].nodeName !== "#text"){ console.log(root.childNodes[i]); } } }else{ var p = document.createElement("p"); p.innerHTML = "文本数据"; root.appendChild(p); }
</script> </body></html>1234567891011121314151617181920212223242526272829<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="root"></div> <ul id="list"> <li>列表1</li> <li>列表2</li> <li>列表3</li> </ul>
<script>
var root = document.getElementById("root"); var list = document.getElementById("list"); var result = list.cloneNode(true); root.appendChild(result)
</script>
</body></html>123456789101112131415161718192021222324252627282930313233343536<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="root"> <p id="text1">我是文本</p> </div>
<p id="text3">clone文本</p> <script>
var root = document.getElementById("root"); var text1 = document.getElementById("text1");
var text2 = document.createElement("p"); text2.innerHTML = "新的插入内容";
root.insertBefore(text2,text1);// 将text2插入到text1的前面
var text3 = document.getElementById("text3");
var result = text3.cloneNode(true); root.insertBefore(result,text1);
</script>
</body></html>123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="root"> <p>Hello</p> </div>
<ul id="list"> <li>内容1</li> <li>内容2</li> <li>内容3</li> <li>内容4</li> </ul>
<script>
// var root = document.getElementById("root"); // // var p = document.getElementsByTagName("p")[0]; // var p = document.querySelector("p");
// // root.removeChild(p); // // console.log(p.parentNode); // p.parentNode.removeChild(p);
var list = document.getElementById("list");
console.log(list.childNodes);
// 1. 总节点是9个:#text 和 li节点 // 2. 我们的在循环的时候,在做删除操作,每次删除,你的list.childNodes.length在减少 // 3. 每次都是删除第一个元素:list.childNodes[0]
var len = list.childNodes.length;
for(var i = 0;i<len;i++){ list.removeChild(list.childNodes[0]) }
</script> </body></html>123456789101112131415161718192021222324252627282930313233<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title></head><body>
<div id="root"> <h3 id="title">标题</h3> <h3 id="content">文本信息</h3> </div>
<script>
var root = document.getElementById("root"); var content = document.getElementById("content");
// 创建新节点 var newContent = document.createElement("p"); newContent.textContent = "新的内容";
// var reuslt = root.replaceChild(newContent,content); // console.log(reuslt); // <h3 id="content">文本信息</h3>
content.parentNode.replaceChild(newContent,content)
</script> </body></html>.gitattributes+4
BOM/.DS_StoreAdded
BOM/01_BOM概述.htmlAdded+22
BOM/02_script工作原理.htmlAdded+18
BOM/03_回流和重绘.htmlAdded+43
BOM/04_定时器1_setTimeout.htmlAdded+66
BOM/04_定时器2_setInterval.htmlAdded+55
BOM/04_定时器3_实操.htmlAdded+34
BOM/04_定时器4_防抖debounce.htmlAdded+82
BOM/04_定时器5_节流throttle.htmlAdded+56
BOM/05_window对象1_属性.htmlAdded+49
BOM/05_window对象2_方法.htmlAdded+31
BOM/06_Navigator对象.htmlAdded+32
BOM/07_Screen对象.htmlAdded+28
BOM/08_History对象1.htmlAdded+25
BOM/08_History对象2.htmlAdded+24
BOM/09_封装cookie.htmlAdded+53
BOM/10_apply_call_bind函数.htmlAdded+90
BOM/css/tab.cssAdded+60
BOM/js/hello.jsAdded+1
BOM/js/index01.jsAdded+1
BOM/js/index02.jsAdded+3
BOM/js/tab.jsAdded+31
DOM/01_DOM概述.htmlAdded+26
DOM/02_document对象_属性.htmlAdded+46
DOM/03_document对象_方法1_获取元素.htmlAdded+56
DOM/03_document对象_方法2_创建元素.htmlAdded+45
DOM/04_Element对象_属性.htmlAdded+37
DOM/05_Element对象_有关位置的属性1.htmlAdded+56
DOM/05_Element对象_有关位置的属性2.htmlAdded+35
DOM/05_Element对象_有关位置的属性3.htmlAdded+34
DOM/05_Element对象_有关位置的属性4.htmlAdded+47
DOM/06_Element对象_方法.htmlAdded+44
DOM/07_Attribute属性.htmlAdded+35
DOM/08_Text节点.htmlAdded+34
DOM/09_DocumentFragment节点.htmlAdded+33
DOM/10_Node节点属性1_nodeName.htmlAdded+28
DOM/10_Node节点属性2_nodeValue.htmlAdded+23
DOM/10_Node节点属性3_textContent.htmlAdded+25
DOM/10_Node节点属性4_nextSibling.htmlAdded+35
DOM/10_Node节点属性5_previousSibling.htmlAdded+25
DOM/10_Node节点属性6_parentNode.htmlAdded+29
DOM/10_Node节点属性7_firstChild_lastChild.htmlAdded+35
DOM/10_Node节点属性8_childNodes.htmlAdded+36
DOM/11_Node节点方法1_appendChild.htmlAdded+41
DOM/11_Node节点方法2_hasChildNodes.htmlAdded+41
DOM/11_Node节点方法3_cloneNode.htmlAdded+29
DOM/11_Node节点方法4_insertBefore.htmlAdded+36
DOM/11_Node节点方法5_removeChild.htmlAdded+51
DOM/11_Node节点方法6_replaceChild.htmlAdded+33