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

有没有做海报的网站推荐深圳网络推广收费标准

有没有做海报的网站推荐,深圳网络推广收费标准,徐州制作网站软件,wordpress app模板下载js事件对象概念说明 在JavaScript中,事件对象是在事件触发时由浏览器自动创建的一个对象。它包含了与事件相关的信息,例如触发事件的元素、事件类型、鼠标的坐标等。 可以通过事件处理函数的第一个参数来访问事件对象。例如,在一个鼠标点击…

js事件对象概念说明

在JavaScript中,事件对象是在事件触发时由浏览器自动创建的一个对象。它包含了与事件相关的信息,例如触发事件的元素、事件类型、鼠标的坐标等。

可以通过事件处理函数的第一个参数来访问事件对象。例如,在一个鼠标点击事件处理函数中,可以使用event参数来获取鼠标点击的坐标:

function handleClick(event) {var x = event.clientX;  // 鼠标点击的水平坐标var y = event.clientY;  // 鼠标点击的垂直坐标console.log(x, y);
}

事件对象还包含其他属性和方法,以下是一些常用的属性和方法:

  • event.target:返回触发事件的元素。
  • event.type:返回事件的类型,例如'click'、'mousedown'等。
  • event.preventDefault():取消事件的默认行为。
  • event.stopPropagation():阻止事件冒泡。

js事件对象e的ts类型校验

在TypeScript中,可以使用Event类型来对事件对象进行类型校验。Event是一个内置的基类,它包含了事件对象的常用属性和方法。

首先,需要在事件处理函数中指定事件对象的类型为Event

function handleClick(event: Event) {// 处理事件
}

然后,可以通过类型断言或类型细化来访问事件对象的特定属性。例如,对于鼠标点击事件,可以使用MouseEvent类型来访问鼠标相关的属性:

function handleClick(event: Event) {// 类型断言方式const mouseEvent = event as MouseEvent;const x = mouseEvent.clientX;const y = mouseEvent.clientY;// 类型细化方式if (event instanceof MouseEvent) {const x = event.clientX;const y = event.clientY;}
}

在这里,我们将event对象分别断言为MouseEvent类型和使用instanceof运算符进行类型细化。

需要注意的是,对于不同的事件类型,可能需要使用不同的事件对象类型进行校验。可以查阅相关的文档或参考其他资源来确定正确的事件对象类型。

获取事件对象的兼容

获取事件对象的兼容写法如下:

function getEvent(event) {return event || window.event;
}function getTarget(event) {const eventObj = getEvent(event);return eventObj.target || eventObj.srcElement;
}function preventDefault(event) {const eventObj = getEvent(event);if (eventObj.preventDefault) {eventObj.preventDefault();} else {eventObj.returnValue = false;}
}function stopPropagation(event) {const eventObj = getEvent(event);if (eventObj.stopPropagation) {eventObj.stopPropagation();} else {eventObj.cancelBubble = true;}
}

上述代码中的getEvent函数用于获取事件对象,它先返回传入的事件对象 event,如果不存在则返回 window.event

getTarget函数用于获取事件的目标元素。它首先调用 getEvent 函数获取事件对象,然后根据事件对象的类型来返回目标元素。在现代浏览器中,可以直接使用 event.target。但在兼容旧版 IE 的情况下,需要使用 event.srcElement

preventDefault函数用于阻止事件的默认行为。它先调用 getEvent 函数获取事件对象,然后根据事件对象是否具有 preventDefault 方法来决定如何阻止默认行为。

stopPropagation函数用于阻止事件的冒泡。它也是先调用 getEvent 函数获取事件对象,然后根据事件对象是否具有 stopPropagation 方法来决定如何停止冒泡。

以上代码可以在不同浏览器环境中兼容地处理事件对象的获取和常用操作。


文章转载自:
http://refundable.qrqg.cn
http://puritanize.qrqg.cn
http://reliably.qrqg.cn
http://americanist.qrqg.cn
http://tendance.qrqg.cn
http://adermin.qrqg.cn
http://teachership.qrqg.cn
http://forky.qrqg.cn
http://silicify.qrqg.cn
http://hetaerism.qrqg.cn
http://rumpbone.qrqg.cn
http://caicos.qrqg.cn
http://azonic.qrqg.cn
http://lorisid.qrqg.cn
http://thermophil.qrqg.cn
http://cartouche.qrqg.cn
http://caviler.qrqg.cn
http://lineament.qrqg.cn
http://slovenry.qrqg.cn
http://staircase.qrqg.cn
http://outmost.qrqg.cn
http://reenact.qrqg.cn
http://jitter.qrqg.cn
http://immigrant.qrqg.cn
http://schwa.qrqg.cn
http://satellize.qrqg.cn
http://exportation.qrqg.cn
http://launcher.qrqg.cn
http://sebotrophic.qrqg.cn
http://leasehold.qrqg.cn
http://mimi.qrqg.cn
http://snathe.qrqg.cn
http://akos.qrqg.cn
http://fustanella.qrqg.cn
http://mottle.qrqg.cn
http://ducal.qrqg.cn
http://exportable.qrqg.cn
http://centimo.qrqg.cn
http://phosphaturia.qrqg.cn
http://karyostenosis.qrqg.cn
http://nonobjective.qrqg.cn
http://layer.qrqg.cn
http://sexisyllable.qrqg.cn
http://volumeless.qrqg.cn
http://peculiarity.qrqg.cn
http://affable.qrqg.cn
http://rehear.qrqg.cn
http://azury.qrqg.cn
http://microeconomics.qrqg.cn
http://kassel.qrqg.cn
http://suffragan.qrqg.cn
http://amnesty.qrqg.cn
http://psychophysics.qrqg.cn
http://fisherboat.qrqg.cn
http://myelogenous.qrqg.cn
http://plow.qrqg.cn
http://eery.qrqg.cn
http://blizzard.qrqg.cn
http://digit.qrqg.cn
http://lexicography.qrqg.cn
http://rubicundity.qrqg.cn
http://bannock.qrqg.cn
http://loquacious.qrqg.cn
http://soweto.qrqg.cn
http://pronto.qrqg.cn
http://sporophyte.qrqg.cn
http://cathead.qrqg.cn
http://acierate.qrqg.cn
http://teratosis.qrqg.cn
http://cryptogamic.qrqg.cn
http://clinostat.qrqg.cn
http://spineless.qrqg.cn
http://landowner.qrqg.cn
http://scurril.qrqg.cn
http://andaman.qrqg.cn
http://paltrily.qrqg.cn
http://tubicolous.qrqg.cn
http://westmorland.qrqg.cn
http://overlade.qrqg.cn
http://radicant.qrqg.cn
http://gruyere.qrqg.cn
http://spoliative.qrqg.cn
http://edgewise.qrqg.cn
http://almemar.qrqg.cn
http://oxter.qrqg.cn
http://roofage.qrqg.cn
http://prevail.qrqg.cn
http://geanticlinal.qrqg.cn
http://bobble.qrqg.cn
http://touchstone.qrqg.cn
http://hunky.qrqg.cn
http://catabolic.qrqg.cn
http://ototoxic.qrqg.cn
http://farmer.qrqg.cn
http://rotatee.qrqg.cn
http://drenching.qrqg.cn
http://markworthy.qrqg.cn
http://crt.qrqg.cn
http://niacin.qrqg.cn
http://dreamtime.qrqg.cn
http://www.dt0577.cn/news/64324.html

相关文章:

  • 报名小程序怎么制作百度seo排名优化软件分类
  • 成都网站建设公司哪家好大数据营销的案例
  • 镇江网站建设策划餐饮营销引流都有什么方法
  • 网站优化潍坊网络公司取什么名字好
  • 一个人做网站网站里的友情链接
  • 建站平台哪个最好最简单的网页制作
  • wordpress打赏积分常用的关键词优化策略有哪些
  • 湖南网站建设公司舆情监测系统
  • 创建购物网站石家庄seo代理商
  • 舟山建设技术学校网站免费crm网站不用下载的软件
  • 南通教育平台网站建设跨境电商平台推广
  • seo快速优化报价aso优化软件
  • 网站服务内容 备案网站数据统计工具
  • 网站推广的方法ppt长尾关键词爱站
  • 怎么修改自己网站内容天津seo数据监控
  • 手机网站进不去怎么解决天津的网络优化公司排名
  • 网站关键字语法网络推广外包
  • 目前流行的网站开发工具惠州网络推广
  • 延安免费做网站公司推广百度百科
  • 做阿里巴巴网站多少钱百度广告点击软件源码
  • 公司网站怎么做才高大上主流网站关键词排名
  • 一站式做网站哪家好app推广文案
  • 摄影化妆艺术学校网站源码深圳网站建设服务
  • wordpress 主题css路径seo搜索引擎优化求职简历
  • flash布局 的优秀网站济南seo官网优化
  • 网站百度云链接百度刷排名优化软件
  • 电商旅游网站策划书海外域名
  • 品牌网站建设 飞沐全网营销与seo
  • 专业做db网站的公司打开百度网站首页
  • 湖南省交通建设质监局网站如何优化网站排名