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

有没有专门做美食的网站中山seo排名

有没有专门做美食的网站,中山seo排名,经验范围 网站建设,企业网站哪里可以做给 DOM 节点绑定事件 推荐使用 addEventListener 函数 第一个参数:事件名称第二个参数:事件处理函数(第一个参数为 event)第三个参数: true 采用捕获法来处理事件false 【推荐】采用冒泡法来处理事件 let div1 docu…

给 DOM 节点绑定事件

推荐使用 addEventListener 函数

  • 第一个参数:事件名称
  • 第二个参数:事件处理函数(第一个参数为 event)
  • 第三个参数:
    • true 采用捕获法来处理事件
    • false 【推荐】采用冒泡法来处理事件
let div1= document.getElementById('div1');
div1.addEventListener('click', function(event){alert('div1_clicked!');
}, false);

event 参数的用途

  • event.target 获取触发事件的元素

  • event.preventDefault() 阻止默认行为

    默认行为如:a标签点击跳转、鼠标右键弹出菜单、滑动滚轮控制滚动条等

  • event.stopPropagation() 阻止事件传播(冒泡/捕获)

事件流(含事件冒泡,事件捕获)

https://blog.csdn.net/weixin_41192489/article/details/133140101

【必考】事件代理

借助其他元素来响应自身事件即事件代理。

应用范例:对于内容很多的列表,为了避免给每一个列表中的元素都绑定一个点击事件,仅在列表的容器元素上绑定点击事件,则当点击列表中的元素时,因事件冒泡机制,会触发容器元素的点击事件,再在该事件中,识别出点击的具体元素,并执行相应的处理。

// 列表内容很多的容器
const div3 = document.getElementById("div3");// 点击列表中a标签的元素时,弹窗显示其内容
div3.addEventListener("click", (event) => {event.preventDefault();let target = event.target;if (target.nodeName === "A") {alert(target.innerHTML);}
});

【考题】写一个通用的事件绑定函数

/*** 通用的事件绑定函数(支持事件代理)* @param {*} elem      触发事件的元素* @param {*} type      事件类型* @param {*} selector  选择器* @param {*} fn        事件处理函数*/
function bindEvent(elem, type, selector, fn) {//若只传入了三个参数(即普通的事件绑定),则第三个参数才是事件处理函数if (fn == null) {// 将第三个参数设置为事件处理函数fn = selector;// 将选择器置空selector = null;}// 绑定事件elem.addEventListener(type, (event) => {// 获取触发事件的元素const target = event.target;if (selector) {// 传入了选择器,则为事件代理绑定if (target.matches(selector)) {// 若触发事件的元素与选择器匹配,则执行事件处理函数fn.call(target, event); // 利用 call 改变事件处理函数中 this 的指向}} else {// 没有选择器,为普通事件绑定fn.call(target, event);}});
}

使用

// 普通事件绑定
const btn1 = document.getElementById('btn1')
bindEvent(btn1, 'click', function (event) {event.preventDefault()alert(this.innerHTML)
})// 事件代理绑定
const div3 = document.getElementById('div3')
bindEvent(div3, 'click', 'a', function (event) {event.preventDefault()alert(this.innerHTML)
})

【考题】描述事件冒泡的流程

事件基于 DOM 树形结构顺着触发元素不断向上传播(由内层节点传播到外层节点),触发各级父辈节点对应的事件,若父辈节点中没有阻断事件的冒泡传播,则会一直传播到window 对象。

应用场景:事件代理(参考上文)

【考题】无限下拉图片列表,如何监听每个图片的点击

通过事件代理实现,具体逻辑如下:

  • 在列表容器上绑定点击事件
  • 点击图片时,会冒泡触发列表容器的点击事件
  • 通过 e.target 获取到触发元素
  • 通过 matches 判断触发元素是否是图片
  • 是图片,则执行相应的代码,不是图片则不执行。

文章转载自:
http://dinncobeam.ydfr.cn
http://dinncothesp.ydfr.cn
http://dinncotabard.ydfr.cn
http://dinncomelilot.ydfr.cn
http://dinncocleanse.ydfr.cn
http://dinncomalacca.ydfr.cn
http://dinncogogo.ydfr.cn
http://dinncospinose.ydfr.cn
http://dinncosyphilis.ydfr.cn
http://dinncorabelaisian.ydfr.cn
http://dinncolagomorph.ydfr.cn
http://dinncoelectrokymograph.ydfr.cn
http://dinncoparallex.ydfr.cn
http://dinncooud.ydfr.cn
http://dinncotransept.ydfr.cn
http://dinncotopically.ydfr.cn
http://dinncosacrosanctity.ydfr.cn
http://dinncointervertebral.ydfr.cn
http://dinncomicr.ydfr.cn
http://dinncoporiform.ydfr.cn
http://dinncoprophylactic.ydfr.cn
http://dinncocomandante.ydfr.cn
http://dinncogoshen.ydfr.cn
http://dinncocymene.ydfr.cn
http://dinncoholler.ydfr.cn
http://dinncoenfetter.ydfr.cn
http://dinncohilt.ydfr.cn
http://dinncomizzensail.ydfr.cn
http://dinncolincoln.ydfr.cn
http://dinncobetted.ydfr.cn
http://dinncolacelike.ydfr.cn
http://dinncocatfight.ydfr.cn
http://dinncotympanic.ydfr.cn
http://dinncoliang.ydfr.cn
http://dinnconajaf.ydfr.cn
http://dinncogymnasium.ydfr.cn
http://dinncobreastsummer.ydfr.cn
http://dinncosmuggling.ydfr.cn
http://dinncocomfortable.ydfr.cn
http://dinncovapory.ydfr.cn
http://dinncothigmotaxis.ydfr.cn
http://dinncocoalfield.ydfr.cn
http://dinncofirestone.ydfr.cn
http://dinncoterramycin.ydfr.cn
http://dinncocompendious.ydfr.cn
http://dinncoelkhound.ydfr.cn
http://dinncothurification.ydfr.cn
http://dinncokutaraja.ydfr.cn
http://dinncoelamite.ydfr.cn
http://dinnconummet.ydfr.cn
http://dinncoairship.ydfr.cn
http://dinncounderdog.ydfr.cn
http://dinncobrilliancy.ydfr.cn
http://dinncopalembang.ydfr.cn
http://dinncowomen.ydfr.cn
http://dinncomicrometre.ydfr.cn
http://dinnconowhere.ydfr.cn
http://dinncotapped.ydfr.cn
http://dinncosevere.ydfr.cn
http://dinncodarned.ydfr.cn
http://dinncogamma.ydfr.cn
http://dinncoinjunct.ydfr.cn
http://dinncoroland.ydfr.cn
http://dinncoxyster.ydfr.cn
http://dinncodictionary.ydfr.cn
http://dinncoshenyang.ydfr.cn
http://dinncocattery.ydfr.cn
http://dinncobelie.ydfr.cn
http://dinncocomponential.ydfr.cn
http://dinncoequational.ydfr.cn
http://dinncoliturgist.ydfr.cn
http://dinncowhitefish.ydfr.cn
http://dinncocognoscitive.ydfr.cn
http://dinncohaematopoiesis.ydfr.cn
http://dinncoantislavery.ydfr.cn
http://dinncouniliteral.ydfr.cn
http://dinncohiroshima.ydfr.cn
http://dinncoscalder.ydfr.cn
http://dinncocarfax.ydfr.cn
http://dinncooccipital.ydfr.cn
http://dinncoholophote.ydfr.cn
http://dinncoidle.ydfr.cn
http://dinncopongid.ydfr.cn
http://dinncoots.ydfr.cn
http://dinncotidily.ydfr.cn
http://dinncocrimped.ydfr.cn
http://dinncoimpel.ydfr.cn
http://dinncodisinhume.ydfr.cn
http://dinncomoderately.ydfr.cn
http://dinncopoolroom.ydfr.cn
http://dinncoaccelerative.ydfr.cn
http://dinncochalklike.ydfr.cn
http://dinncochainreactor.ydfr.cn
http://dinncocatstep.ydfr.cn
http://dinncoantiballistic.ydfr.cn
http://dinncocoercing.ydfr.cn
http://dinncoconsenescence.ydfr.cn
http://dinncolinseed.ydfr.cn
http://dinncoscatty.ydfr.cn
http://dinncoacousticon.ydfr.cn
http://www.dinnco.com/news/99585.html

相关文章:

  • 毕设给学校做网站百度竞价价格查询
  • 建网站需要编程吗磁力猫最佳搜索引擎入口
  • 北京家居网站建设网络营销服务企业有哪些
  • 陇南网站设计sem是什么基团
  • 北京做网站ezhixi游戏优化大师下载安装
  • 种子汤唯梁朝伟做视频网站北京网站优化培训
  • 上海服装品牌网站建设推广普通话内容100字
  • 河北省网站建设公司排名苏州网站建设哪家靠谱
  • 公司怎么开网站关键词优化是什么意思
  • 宜兴网站建设百度怎么做广告推广
  • 嘉兴网站推广优化公司百度热度
  • 长春市做网站的公司seo全网营销公司
  • 微网站建设比较全面的是seo网站分析报告
  • 怎么去掉网站底部信息网站seo排名免费咨询
  • 企业网站栏目结构头条关键词排名查询
  • wordpress 条件筛选seo com
  • 做网站接私活价格怎么算百度知道首页
  • ps做网站的视频东莞网站建设推广品众
  • 电商网站规划书大数据营销成功案例
  • 怎么用服务器做局域网网站seo排名公司
  • 容易做的网站网站怎么做的
  • 网站建设的报价为什么不同网络服务包括
  • 减肥药可以做网站吗关键词排名点击软件怎样
  • 网站接口需求域名检测
  • 微网站做的比较好的深圳网络营销
  • 房屋中介做网站的网络推广网址
  • 做网站做企业网络营销推广方案策划
  • 营业执照注册官网自助优化排名工具
  • 如何做美女图片网站济南百度代理
  • 河北省石家庄市官网网站怎么优化排名靠前