摘要:index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script> document.addEventListener("DOMContentLoaded", function () { console.log(doc
阅读全文
摘要:index.js const root = document.getElementById('root') root.innerHTML = ` <h1>hello</h1> <strong> <span>world</span> </strong> `
阅读全文
摘要:index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> </head> <body> <button id="btn1">打开窗口</button> <button id="btn2">检测</button> <script
阅读全文
摘要:index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> </head> <body> <button onclick="clickHandler()">open: sub.html</button> <script> //
阅读全文
摘要:window.onpopstate = function(res) { console.log(res) } 注意: pushState()或replaceState()不能触发该事件; 用户点击前进、后退,或 History.back()、History.forward()、History.go(
阅读全文
摘要:index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> </head> <body> <h3>Hello, World!</h3> <script> const finalStyleObject = window.getCo
阅读全文
摘要:index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> </head> <body> <div>Hello, World!</div> <script> window.onmouseup = function () { co
阅读全文
摘要:index.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> </head> <body> <h1> <iframe src="./sub.html" frameborder="0"></iframe> </h1> </body>
阅读全文
摘要:index.html <script id="script"> // .text || .innerText || .innerHTML alert(document.getElementById("script").text); </script>
阅读全文
摘要:index.js const img = document.createElement('img') // const img = new Image() img.classList.add('avatar')
阅读全文
摘要:元素节点的滚动有三种方法: 1. Element.scrollTop, 表示滚动到距离顶部多少像素 2. Element.scrollLeft, 表示滚动到距离左边多少像素 3. Element.scrollIntoView() 表示滚动到和页面的可视区域, 即视口, 和锚点定位类似.
阅读全文
摘要:使用 Element.prototype.attributes
阅读全文
摘要:使用: Element.prototype.isContentEditable, 可以判断某个元素节点是否可编辑. 注意: 1. Element.prototype.isContentEditable 只读; 有 true / false / inherit 2. Element.prototype
阅读全文
摘要:1. 可以在html中写死,如下: 2. 可以使用 Element.prototype.title 属性动态设置:
阅读全文
摘要:使用: Element.prototype.lang; 比如: 注意: 1. 每个元素节点都有一个lang属性, 必须要显式声明才会有返回值, 否则返回空字符串""; 2. Element.prototype.lang 属性是可读写的;
阅读全文
摘要:元素的可拖动属性为: draggable. 默认为false, 可以通过: Element.prototype.draggable; 查看与修改; 注意: 该属性可读写;
阅读全文
摘要:使用 Element.prototype.accesskey 注意: 快捷键用Alt+x触发, 会将焦点聚焦到目标元素上
阅读全文
摘要:比如通过id获取的一个元素节点, 想知道这个节点是什么什么标签, 这时可以通过: Node.prototype.nodeName属性 或 Element.prototype.tagName属性获取. 注意: tagName和nodeName返回的结果是完全一样的, 只是tagName在Element
阅读全文
摘要:使用 el.id; el表示获取到的元素节点, 如下所示: 注意: 1. el.id 属性可读可写; 2. 对id的修改会实时反映到DOM树中; 3. id值对大小写敏感, app 和 APP 是两个不同的id, 建议都写成小写.
阅读全文
摘要:需要使用到三个document方法: 1. document.execCommand(); 执行某个命令 2. document.queryCommandSupported(); 检测浏览器是否支持某个命令 3. document.queryCommandEnabled(); 检测当前状态下某个命令
阅读全文