摘要: 获取元素: // 在低版本ie不兼容 document.getElementsByClassName() document.querySelector() document.querySelectorAll() // 兼容 document.getElementById() document.get 阅读全文
posted @ 2021-01-12 16:10 技术活当赏 阅读(82) 评论(0) 推荐(0)
摘要: 短路运算 - 赋值操作 var b = a>5 && 5; // 能运行到5,所以会把5赋值给b console.log(b); var b = a<5 && 5; // 只能运行到a<5,就把a<5赋值给了b console.log(b); // false var b = a>5 || 6; / 阅读全文
posted @ 2021-01-12 16:00 技术活当赏 阅读(95) 评论(0) 推荐(0)
摘要: 事件委托:将子标签的事件委托给父元素去处理 var btn = document.querySelector("button"); var ul = document.querySelector("ul"); btn.onclick = function(){ var li = document.c 阅读全文
posted @ 2021-01-12 15:49 技术活当赏 阅读(59) 评论(0) 推荐(0)
摘要: 默认行为 不需要写js代码也能执行的一些行为,如:a标签点击就能跳转、form提交、鼠标右击 .... 阻止默认行为 阻止a标签\form标签也是3种办法 1.将a标签的href改了 2.在a标签的点击事件的最后,加上 return false 3.利用事件对象 document.querySele 阅读全文
posted @ 2021-01-12 15:45 技术活当赏 阅读(119) 评论(0) 推荐(0)
摘要: 键盘码:键盘中每个键,都有属于自己的码 - 用来区分 事件对象.keyCode document.onkeydown = function(e){ var e = e || window.event; // console.log(e.keyCode); // // 低版本火狐中有兼容问题 // c 阅读全文
posted @ 2021-01-12 15:40 技术活当赏 阅读(175) 评论(0) 推荐(0)
摘要: 拖拽div的代码 var box = document.querySelector(".box"); box.onmousedown = function(e){ // 鼠标按下就应该获取到光标在div上的位置 // var e = e || window.event; // var x = e.o 阅读全文
posted @ 2021-01-12 15:31 技术活当赏 阅读(82) 评论(0) 推荐(0)
摘要: 光标位置 光标位置 - clientX clientY - 相对于浏览器的位置 var box = document.querySelector(".box"); box.onclick = function(e){ var e = e || window.event; // 光标位置 - clie 阅读全文
posted @ 2021-01-12 15:30 技术活当赏 阅读(86) 评论(0) 推荐(0)
摘要: 事件对象在低版本ie中不兼容的 var ev = window.event; 兼容的获取事件对象 var e = e || window.event; 利用事件对象阻止事件冒泡 e.stopPropagation() 在低版本ie中,阻止冒泡的方法也不兼容 ev.cancelBubble = tru 阅读全文
posted @ 2021-01-12 15:25 技术活当赏 阅读(87) 评论(0) 推荐(0)
摘要: 事件对象:一个对象,系统提供的,描述事件的所有信息,比如:事件类型、鼠标位置、按键、键盘码.... 事件函数,是由系统调用的,咱们自己没办法调用的,也就是不可能传入实参,没有实参,事件函数也就不可能有形参,-形参没有意义,函数由系统调用,系统可以给这个函数加一个实参,实参就是一个对象 - 事件对象 阅读全文
posted @ 2021-01-12 15:18 技术活当赏 阅读(83) 评论(0) 推荐(0)
摘要: 操作html console.log(document.documentElement); //输出这个属性 操作body console.log( document.body ); 操作head console.log( document.head ); 操作title console.log( 阅读全文
posted @ 2021-01-11 21:30 技术活当赏 阅读(80) 评论(0) 推荐(0)