首页 > 其他分享 >simpread-TypeScript DOM 类型的声明

simpread-TypeScript DOM 类型的声明

时间:2022-11-20 14:57:43浏览次数:76  
标签:canvas TypeScript const img DOM HTMLInputElement HTMLElement HTMLHeadingElement 

TS DOM 类型的声明

lib.dom.d.ts

HTMLInputElement

<input type="text" @change="handleChange" />
const handleChange = (evt: Event) => {
    console.log((evt.target as HTMLInputElement).value);
}
  1. image-20221120144043038

    要想拿到.value属性,那么就是要as HTMLInputElement

  2. 一般来说,as HTMLElment就行了,但是为了拿到具体的一些属性,就是必须具体这个元素的类型

HTMLElement

const div: HTMLDivElement = document.createElement('div');
const img: HTMLImageElement = document.createElement('img');

// canvas
const canvas:HTMLCanvasElement = document.createElement('canvas');
const ctx:CanvasRenderingContext2D = canvas.getContext('2d');
  1. image-20221120144259786
interface HTMLElementTagNameMap {
    "a": HTMLAnchorElement;
    "abbr": HTMLElement;
    "address": HTMLElement;
    "applet": HTMLAppletElement;
    "area": HTMLAreaElement;
    "article": HTMLElement;
    "aside": HTMLElement;
    "audio": HTMLAudioElement;
    "b": HTMLElement;
    "base": HTMLBaseElement;
    "basefont": HTMLBaseFontElement;
    "bdi": HTMLElement;
    "bdo": HTMLElement;
    "blockquote": HTMLQuoteElement;
    "body": HTMLBodyElement;
    "br": HTMLBRElement;
    "button": HTMLButtonElement;
    "canvas": HTMLCanvasElement;
    "caption": HTMLTableCaptionElement;
    "cite": HTMLElement;
    "code": HTMLElement;
    "col": HTMLTableColElement;
    "colgroup": HTMLTableColElement;
    "data": HTMLDataElement;
    "datalist": HTMLDataListElement;
    "dd": HTMLElement;
    "del": HTMLModElement;
    "details": HTMLDetailsElement;
    "dfn": HTMLElement;
    "dialog": HTMLDialogElement;
    "dir": HTMLDirectoryElement;
    "div": HTMLDivElement;
    "dl": HTMLDListElement;
    "dt": HTMLElement;
    "em": HTMLElement;
    "embed": HTMLEmbedElement;
    "fieldset": HTMLFieldSetElement;
    "figcaption": HTMLElement;
    "figure": HTMLElement;
    "font": HTMLFontElement;
    "footer": HTMLElement;
    "form": HTMLFormElement;
    "frame": HTMLFrameElement;
    "frameset": HTMLFrameSetElement;
    "h1": HTMLHeadingElement;
    "h2": HTMLHeadingElement;
    "h3": HTMLHeadingElement;
    "h4": HTMLHeadingElement;
    "h5": HTMLHeadingElement;
    "h6": HTMLHeadingElement;
    "head": HTMLHeadElement;
    "header": HTMLElement;
    "hgroup": HTMLElement;
    "hr": HTMLHRElement;
    "html": HTMLHtmlElement;
    "i": HTMLElement;
    "iframe": HTMLIFrameElement;
    "img": HTMLImageElement;
    "input": HTMLInputElement;
    "ins": HTMLModElement;
    "kbd": HTMLElement;
    "label": HTMLLabelElement;
    "legend": HTMLLegendElement;
    "li": HTMLLIElement;
    "link": HTMLLinkElement;
    "main": HTMLElement;
    "map": HTMLMapElement;
    "mark": HTMLElement;
    "marquee": HTMLMarqueeElement;
    "menu": HTMLMenuElement;
    "meta": HTMLMetaElement;
    "meter": HTMLMeterElement;
    "nav": HTMLElement;
    "noscript": HTMLElement;
    "object": HTMLObjectElement;
    "ol": HTMLOListElement;
    "optgroup": HTMLOptGroupElement;
    "option": HTMLOptionElement;
    "output": HTMLOutputElement;
    "p": HTMLParagraphElement;
    "param": HTMLParamElement;
    "picture": HTMLPictureElement;
    "pre": HTMLPreElement;
    "progress": HTMLProgressElement;
    "q": HTMLQuoteElement;
    "rp": HTMLElement;
    "rt": HTMLElement;
    "ruby": HTMLElement;
    "s": HTMLElement;
    "samp": HTMLElement;
    "script": HTMLScriptElement;
    "section": HTMLElement;
    "select": HTMLSelectElement;
    "slot": HTMLSlotElement;
    "small": HTMLElement;
    "source": HTMLSourceElement;
    "span": HTMLSpanElement;
    "strong": HTMLElement;
    "style": HTMLStyleElement;
    "sub": HTMLElement;
    "summary": HTMLElement;
    "sup": HTMLElement;
    "table": HTMLTableElement;
    "tbody": HTMLTableSectionElement;
    "td": HTMLTableDataCellElement;
    "template": HTMLTemplateElement;
    "textarea": HTMLTextAreaElement;
    "tfoot": HTMLTableSectionElement;
    "th": HTMLTableHeaderCellElement;
    "thead": HTMLTableSectionElement;
    "time": HTMLTimeElement;
    "title": HTMLTitleElement;
    "tr": HTMLTableRowElement;
    "track": HTMLTrackElement;
    "u": HTMLElement;
    "ul": HTMLUListElement;
    "var": HTMLElement;
    "video": HTMLVideoElement;
    "wbr": HTMLElement;
}

本文由 简悦 SimpRead 转码, 原文地址 juejin.cn

标签:canvas,TypeScript,const,img,DOM,HTMLInputElement,HTMLElement,HTMLHeadingElement,
From: https://www.cnblogs.com/zhuoss/p/16908468.html

相关文章

  • How to find event listeners on a DOM node in JavaScript or in debugging?
    HowtofindeventlistenersonaDOMnodeinJavaScriptorindebugging?回答1Chrome,Firefox,VivaldiandSafarisupportgetEventListeners(domElement)inth......
  • 虚拟dom和diff算法
    虚拟dom和diff算法1.虚拟dom是一个能代表DOM树的对象,通常含有标签名,标签上的属性、事件监听和子元素们和子元素们的属性2.虚拟dom优点,能减少不必要的DOM操作,能跨平台渲染......
  • Vue XQTypeScriptFramework 使用
    说明XQTypeScriptFramework隶属于XQFramework下JS基础性框架部分XQFramework励志将开发将常用开发语音基础性框架统一汇总,为全站开发使用到的基础语法进行统一,拜......
  • vue2 echarts 报错 mounted Initialize failed: invalid dom. 的一种解决方法
    如题参考了https://blog.csdn.net/weixin_52418790/article/details/123690752但是还是不行,后来发现我这个是在elementui的模态框里面写的,但是模态框还没有......
  • [Typescript] 111. Hard - String Join
    Createatype-safestringjoinutilitywhichcanbeusedlikeso:consthyphenJoiner=join('-')constresult=hyphenJoiner('a','b','c');//='a-b-c'Or......
  • GKCTF2020-domo
    例行检查全绿,64位保护全开。动态分析增删查改四个功能增删查改改这个功能没太勘定似乎是需要我们输入一个地址去修改,这好像就造成了任意地址写,不太确定,稍后通......
  • DOM_Element对象以及Node对象
    DOM_Element对象Element:元素对象获取/创建:通过document来获取和创建方法:removeAttribute():删除属性setAttribute():添加新属性<body><......
  • DOM_Document对象获取Element方法以及创建DOM对象
    DOM_Document对象获取Element方法Document:文档对象创建(获取):在htmldom模型中使用window对象来获取window.documentdocument方法:......
  • TypeScript 复习与进阶三部曲 (3) – TypeScript 类型体操
    前言在 第一部–把TypeScript当强类型语言使用 和 第二部– 把TypeScript当编程语言使用 后,我们几乎已经把TypeScript的招数学完了.第三部就要开始做练......
  • BOM案例_自动跳转首页和DOM概述
    案例_自动跳转首页分析:1.显示页面效果<p>2.倒计时读秒效果实现定义一个方法,来获取span标签,修改span标签体内容定义一个定时器,1秒执行一......