您当前的位置: 首页 >  html

暂无认证

  • 2浏览

    0关注

    93637博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

jsDOM逐步实现原生事件机制(html逻辑 css逻辑 js逻辑)

发布时间:2020-10-19 22:56:26 ,浏览量:2

css:

body { overflow: hidden; } div { padding: 100px; } .one { background: thistle; } .two { background: mistyrose; } .three { background: coral; } 

html:

		
"one">
"two">
"three">

在这里插入图片描述 js逻辑: 第一步:

let divs = document.querySelectorAll('div'); let one = document.querySelector('.one'); let two = document.querySelector('.two'); let three = document.querySelector('.three'); 

第一步;获取节点,要用得拿到是吧

divs.forEach(div => div.addEventListener('click', logText, { once: true, capture: false })); 

第二步;once: true,点击一个执行一个. capture: false是只执行对应层.

function logText(e) { console.log(this.classList.value); e.stopPropagation(); } 
关注
打赏
1655258400
查看更多评论
立即登录/注册

微信扫码登录

0.0794s