HTML常用标签

78 阅读1分钟

a标签的用法

  1. 属性
  • href

    • 网址 google.comgoogle.com : http:// 表协议
      //google.com : 协议继承当前窗口
    • 路径 /a/b/c 与 a/b/c : 前者/表根目录,在http里表当前目录,后者为相对路径,相对于当前目录
    • 伪协议 javascript:代码;
      mailto:邮箱;
      tel:手机号;
    • 锚点 href=#xxx : xxx是元素的id
  • target 默认为_self

    • _blank

    新窗口中打开

    • _top

    最上层窗口中打开

    • _parent

    父窗口中打开

    • _self

    默认值,当前窗口中打开

    • 其它

    想要打开的窗口的名字

  • download
    不是打开页面,而是下载页面,浏览器可能不支持

  • rel=noopener
    禁止打开的窗口对原窗口操作,减少安全隐患

img 标签的用法

  • 属性有 alt/height/width/src
    alt : 可替换内容,当图片未加载时显示的文字
  • 事件有 onload / onerror
    利用onerror事件可以监听图片加载失败,从而将其替换成404图片

table 标签的用法

  • 相关的标签有:
    table/ thead/ tbody/ tfoot/ tr/ th/ td
  • 相关的样式有: table-layout border-collapse border-spacing
    table-layout主要取值有 : automatic fixed inherit
    其中automatic为默认值,自动调节表格每列的宽度,fixed为固定每列宽度

form 标签的用法

  • 属性有:
    action/autocomplete/method/target
    其中
    action指定提交的url
    autocomplete可以自动补全input元素
    method指定提交方法是get还是post
    target指定提交表单后在哪里显示响应信息
  • 相关事件有: onsubmit

input 标签的用法

  • 属性有:
    type: button/checkbox/email/file/hidden/number/password/radio/search/submit/tel/text 在form中若未指定button的类型,会默认变为submit
  • 相关事件有: onchange/onfocus/onblur

其他感想

width 读作: "位子"