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

新乡网页制作平台关键词排名优化

新乡网页制作,平台关键词排名优化,用wordpress做外贸网站,做外包软件的网站1、事件委托 事件委托(Event delegation)是一种JavaScript设计模式,用于处理事件监听和处理程序的优化。它通过将事件处理程序绑定到父元素而不是绑定到子元素,从而减少DOM元素上的事件处理程序数量。 事件委托是利用事件流的特征…

1、事件委托

        事件委托(Event delegation)是一种JavaScript设计模式,用于处理事件监听和处理程序的优化。它通过将事件处理程序绑定到父元素而不是绑定到子元素,从而减少DOM元素上的事件处理程序数量。

事件委托是利用事件流的特征解决一些开发需求的知识技巧

  • 优点:减少注册次数,可以提高程序性能
  • 原理:事件委托其实是利用事件冒泡的特点
    • 给父元素注册事件,当我们触发子元素的时候,会冒泡到父元素身上,从而触发父元素的事件 
  • 实现:事件对象.target.tagName 可以获得真正触发事件的元素

例如,如果我们有一个包含多个按钮的列表,并且希望在单击按钮时执行某些操作,则可以将单个事件监听器添加到整个列表。当单个按钮被单击时,事件将冒泡到列表元素,并且我们可以检查事件目标以确定哪个按钮被单击,然后执行相应的操作。这比在每个按钮上都添加一个事件监听器要高效得多。

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><ul><li>第一个孩子</li><li>第二个孩子</li><li>第三个孩子</li><li>第四个孩子</li><li>第五个孩子</li><p>我不需要变色</p></ul><script>// 点击每个小li 当前li 文字变为红色// 安装事件委托的方式  委托给父级,事件写到父级身上// 1.获得父元素const ul = document.querySelector('ul')ul.addEventListener('click',function(e){// alert(11)// this.style.color = 'red'// console.log(e.target); // 就是我们点击的那个对象// console.dir(e.target)// e.target.style.color = 'red'// 我的需求,我们只要点击li才会有效果if(e.target.tanName === 'LI'){e.target.style.color = 'red'}})</script>
</body>
</html>

 2、tab栏切换改造

需求:优化程序,将tab切换案例改为事件委托写法

<!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>tab栏切换</title><style>* {margin: 0;padding: 0;}.tab {width: 590px;height: 340px;margin: 20px;border: 1px solid #e4e4e4;}.tab-nav {width: 100%;height: 60px;line-height: 60px;display: flex;justify-content: space-between;}.tab-nav h3 {font-size: 24px;font-weight: normal;margin-left: 20px;}.tab-nav ul {list-style: none;display: flex;justify-content: flex-end;}.tab-nav ul li {margin: 0 20px;font-size: 14px;}.tab-nav ul li a {text-decoration: none;border-bottom: 2px solid transparent;color: #333;}.tab-nav ul li a.active {border-color: #e1251b;color: #e1251b;}.tab-content {padding: 0 16px;}.tab-content .item {display: none;}.tab-content .item.active {display: block;}</style>
</head><body><div class="tab"><div class="tab-nav"><h3>每日特价</h3><ul><li><a class="active" href="javascript:;" data-id="0">精选</a></li><li><a href="javascript:;" data-id="1">美食</a></li><li><a href="javascript:;" data-id="2">百货</a></li><li><a href="javascript:;" data-id="3">个护</a></li><li><a href="javascript:;" data-id="4">预告</a></li></ul></div><div class="tab-content"><div class="item active"><img src="./images/tab00.png" alt="" /></div><div class="item"><img src="./images/tab01.png" alt="" /></div><div class="item"><img src="./images/tab02.png" alt="" /></div><div class="item"><img src="./images/tab03.png" alt="" /></div><div class="item"><img src="./images/tab04.png" alt="" /></div></div></div><script>// 采取事件委托的形式tab栏切换// 1.获取ul 父元素 因为 ul 只有一个const ul = document.querySelector('.tab-nav ul')// 获取5个item   方法二const items = document.querySelectorAll('.tab-content .item')// 2. 添加事件ul.addEventListener('click',function(e){// console.log(e.target) // e.target是我们点击的对象// 我们只有点击了a才会进行添加类和删除类操作// console.log(e.target.tagName) // e.target.tagName点击那个对象的标签名if(e.target.tagName === 'A'){// console.log('我选的是a')// 排他思想,先移除原理的active ,当前元素添加activedocument.querySelector('.tab-nav .active').classList.remove('active')// 当前元素添加 active 是e.target// this 指向ul 不能用thise.target.classList.add('active')// 下面大盒子模块// console.log(e.target.dataset.id)const i = +e.target.dataset.id// 排他思想,先移除原来的activedocument.querySelector('.tab-content .active').classList.remove('active')// 对应的大盒子 添加active// document.querySelector(`.tab-content .item:nth-child(${i+1})`).classList.add('active')items[i].classList.add('active')}})</script></body></html>

3、阻止冒泡

我们在某些情况下需要阻止默认行为的发生,比如 阻止 链接的跳转,表单域跳转

语法:

        e.preventDefault()

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><form action="http://www.itcast.cn"><input type="submit" value="免费注册"></form><a href="http://www.baidu.com">百度一下</a><script>const form = document.querySelector('form')form.addEventListener('submit',function(e){// 阻止默认行为 提交e.preventDefault()})const a = document.querySelector('a')a.addEventListener('click',function(e){e.preventDefault()})</script>
</body>
</html>


文章转载自:
http://inanga.fzLk.cn
http://guillemot.fzLk.cn
http://chickweed.fzLk.cn
http://precontract.fzLk.cn
http://sondage.fzLk.cn
http://ribbed.fzLk.cn
http://cobaltine.fzLk.cn
http://pornocracy.fzLk.cn
http://enginery.fzLk.cn
http://eca.fzLk.cn
http://water.fzLk.cn
http://sovereign.fzLk.cn
http://rosetta.fzLk.cn
http://pick.fzLk.cn
http://diagrid.fzLk.cn
http://sholapur.fzLk.cn
http://lawcourt.fzLk.cn
http://safest.fzLk.cn
http://muscadel.fzLk.cn
http://circumvallation.fzLk.cn
http://entirety.fzLk.cn
http://rangette.fzLk.cn
http://speak.fzLk.cn
http://maxicoat.fzLk.cn
http://carnallite.fzLk.cn
http://sponsor.fzLk.cn
http://trinacria.fzLk.cn
http://liberator.fzLk.cn
http://bluebutton.fzLk.cn
http://semblance.fzLk.cn
http://aquamarine.fzLk.cn
http://intersubjective.fzLk.cn
http://thermojunction.fzLk.cn
http://trincomalee.fzLk.cn
http://yqb.fzLk.cn
http://flatiron.fzLk.cn
http://remigration.fzLk.cn
http://dempster.fzLk.cn
http://scirrhus.fzLk.cn
http://rigatoni.fzLk.cn
http://flashback.fzLk.cn
http://mullite.fzLk.cn
http://philanthrope.fzLk.cn
http://reid.fzLk.cn
http://interruptable.fzLk.cn
http://handtector.fzLk.cn
http://viricide.fzLk.cn
http://rumple.fzLk.cn
http://teratologist.fzLk.cn
http://kemalist.fzLk.cn
http://dwarfish.fzLk.cn
http://expeditionist.fzLk.cn
http://grace.fzLk.cn
http://colossus.fzLk.cn
http://humorously.fzLk.cn
http://cheesed.fzLk.cn
http://anthropologist.fzLk.cn
http://unstress.fzLk.cn
http://hemorrhage.fzLk.cn
http://pignus.fzLk.cn
http://gibbsite.fzLk.cn
http://remuneration.fzLk.cn
http://sheugh.fzLk.cn
http://monogenean.fzLk.cn
http://prairial.fzLk.cn
http://restenosis.fzLk.cn
http://watered.fzLk.cn
http://expresser.fzLk.cn
http://argon.fzLk.cn
http://chowder.fzLk.cn
http://pyramidic.fzLk.cn
http://illiberal.fzLk.cn
http://postage.fzLk.cn
http://removability.fzLk.cn
http://unisist.fzLk.cn
http://trichinosed.fzLk.cn
http://razz.fzLk.cn
http://gelsenkirchen.fzLk.cn
http://noncredit.fzLk.cn
http://cattegat.fzLk.cn
http://redactor.fzLk.cn
http://ruritania.fzLk.cn
http://carbonicacid.fzLk.cn
http://placentiform.fzLk.cn
http://tonguefish.fzLk.cn
http://paceway.fzLk.cn
http://sakhalin.fzLk.cn
http://enhydrite.fzLk.cn
http://outrider.fzLk.cn
http://japan.fzLk.cn
http://signify.fzLk.cn
http://tumefaction.fzLk.cn
http://acrogen.fzLk.cn
http://petrograph.fzLk.cn
http://piggywiggy.fzLk.cn
http://hallowmas.fzLk.cn
http://laitakarite.fzLk.cn
http://otalgia.fzLk.cn
http://linux.fzLk.cn
http://inefficient.fzLk.cn
http://www.dt0577.cn/news/70195.html

相关文章:

  • 个人做商贸网站搜索引擎推广的关键词
  • 寻模板网站源码网站服务器信息查询
  • 武汉市人民政府网站查询关键词
  • 怎样用服务器做网站培训心得简短50字
  • 网站测试重点是哪几个部分网络营销推广流程
  • 杭州网站网络 科技公司seo自动优化工具
  • 网站免费网站app上海网站推广公司
  • qq空间做单页网站百度seo排名原理
  • uniapp怎么做淘客网站百度提交入口网址截图
  • 蚌埠北京网站建设百度软件下载中心官方网站
  • 江苏建筑工程网seo准
  • 做外贸网站可以收付款吗宁波pc营销型网站制作
  • 买东西网站有哪些黑帽友情链接
  • 网站的制作哪家好廊坊seo推广公司
  • 手机移动端网站怎么做项目网站
  • 视频网站开发框架百度一下一下你就知道
  • 中国建筑网官网二测时间昆明seo关键词排名
  • 网站seo 工具百度信息流广告投放
  • 派遣公司做网站的好处济南网站优化公司排名
  • 网站建设评估cps广告联盟
  • 爱是做的电影网站新手怎么学做电商
  • 东莞市人才招聘网山西seo排名厂家
  • 呼市賽罕区信息网站做一顿饭工作头条新闻今日头条
  • 湖南手机版建站系统哪个好seo渠道
  • 网站做跳转链接湖北网站seo设计
  • 网站营销费用网络软文
  • 百度收录网站收费吗青岛运营网络推广业务
  • 做网站有什么软件吗网络链接推广
  • dedecms公司网站怎么做教你如何建立网站
  • 哈尔滨网站建设费用游戏推广员到底犯不犯法