Table of Contents
前面的话
HTML原有属性
accesskey
class
dir
id
lang
style
tabindex
title
HTML5新增属性
contenteditable
contextmenu(没有浏览器支持)
data-*
draggable(IE8-不支持)
dropzone(所有浏览器都不支持)
hidden(IE7-不支持)
spellcheck(IE9-不支持) 
translate(所有浏览器都不支持)
Home Web Front-end HTML Tutorial HTML的16个全局属性_html/css_WEB-ITnose

HTML的16个全局属性_html/css_WEB-ITnose

Jun 24, 2016 am 11:32 AM

目录 [1]accesskey [2]class [3]dir [4]id [5]lang [6]style [7]tabindex [8]title [9]contenteditable [10]contentmenu [11]data-* [12]draggable [13]dropzone [14]hidden [15]spellcheck [16]translate

前面的话

  在HTML中,属性能表达相当丰富的语义,而且属性也会额外提供很多实用的功能,HTML共支持16个常见的全局属性。

 

HTML原有属性

accesskey

  作用:浏览器用来创建激活或聚焦元素的快捷键

  值:一个键盘字符如 O

  范围:支持该属性的元素有

  注意:使用该属性可能在新窗口打开链接时可能会被浏览器屏蔽

<div>    <a href="http://www.baidu.com" accesskey="b">百度</a>    <a href="http://www.taobao.com" accesskey="a">阿里</a>    <a href="http://www.qq.com" accesskey="t">腾讯</a>        <p>快捷键(alt+b)可以跳转到百度;快捷键(alt+a)可以跳转到阿里;快捷键(alt+t)可以跳转到腾讯</p></div>
Copy after login

class

  作用:规定元素的一个或多个类名

  值:多个类名用空格分隔

  注意:类名不能以数字开头

dir

  作用:文字的方向

  值:ltr/rtl/auto

id

  作用:规定元素的唯一标识

  注意:若浏览器中出现多个id名的情况,CSS样式对所以该id名的元素都生效,但js脚本仅对第一个出现该id名的元素生效

lang

  作用:规定元素内容的语言

  值:en英文/zn中文

style

  作用:设置元素的行间样式

tabindex

  作用:规定元素的tab键次序

  值:(1是第一个)

<div>    <a href="http://www.baidu.com" tabindex="3">百度</a>    <a href="http://www.taobao.com" tabindex="2">阿里</a>    <a href="http://www.qq.com" tabindex="1">腾讯</a>    </div>
Copy after login

 

title

  作用:规定关于元素的额外信息,鼠标移到元素上时显示一段提示文本 

 

 

HTML5新增属性

contenteditable

  作用:指定是否可以在浏览器里编辑内容

  值:true/false

  注意:设置document.designMode ='on'时,页面的任意位置都可以编辑;使用contenteditable ='true'则只对具体元素和其包含的元素起作用

  移动端:移动端ios5以及android3之后才支持该属性

  选中文字后,点击下列相应属性值可进行演示

contextmenu(没有浏览器支持)

  作用:跟元素关联的右键菜单

  值:

元素中唯一ID

 

data-*

  作用:用于存储页面或应用程序的私有定制数据

  注意:属性名不应包含任何大写字母,且在前缀"data-"之后必须有至少一个字符;属性值可以是任意字符串

  使用:可以在所有浏览器中使用getAttribute方法来获取data-*属性的值,也可以使用javascript中dataset属性访问data-*属性的值,不过IE10-浏览器不支持dataset

 

draggable(IE8-不支持)

  作用:用户是否可以拖动元素

  值:true/false/auto

  注意:链接和图像默认是可拖动的

 

dropzone(所有浏览器都不支持)

  作用:规定在拖动被拖动数据时是否进行复制、移动或链接

  值:copy拷贝/move移动/link指向原始数据链接

 

hidden(IE7-不支持)

  作用:显示或隐藏该元素(与display:none的作用一样)

  值:true/false

 

spellcheck(IE9-不支持) 

  作用:规定是否对元素进行拼写和语法检查,对拼写错误的单词会在其下方出现红线

  范围:可编辑区域(表单或contenteditable元素)

  值:true/false

  注意:移动端支持不好

translate(所有浏览器都不支持)

 作用:规定是否应该翻译元素内容

 值:yes/no

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update? Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

How to efficiently add stroke effects to PNG images on web pages? How to efficiently add stroke effects to PNG images on web pages? Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

How do I use the HTML5 <time> element to represent dates and times semantically? How do I use the HTML5 <time> element to represent dates and times semantically? Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 &lt;time&gt; element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

See all articles