Does html5 have new attributes?

青灯夜游
Release: 2023-01-06 11:14:39
Original
3030 people have browsed it

html5 has new attributes, such as contextmenu, contentEditable, hidden, draggable, "data-*", placeholder, required, pattern, autofocus, autocomplete, etc.

Does html5 have new attributes?

The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.

HTML5 new attributes

1.1, contextmenu

The function of contextmenu is to specify the right-click menu.



    
        
        
    
Copy after login

Running effect:

contextmenu In Html5, each element has a new attribute: contextmenu, contextmenu is the context menu, that is, right-click the mouse A menu will appear for the element.
menu To realize that a menu will appear when you right-click an element, you must also understand another new element in HTML5: menu. As the name suggests, menu defines the menu. The menu element attributes: type: menu type attribute. There are three values ​​​​1) context: context; 2) toolbar: toolbar; 3) list: list

Menu items can be embedded inside, that is, < ;menuitem>.
menuitem attributes:
label: the name displayed by the menu item
icon: the icon displayed on the left side of the menu item
onclick: the event triggered by clicking the menu item

1.2 , contentEditable

Specifies whether the content of the element can be edited
Attribute value:
true -----The content of the element can be edited
false -----The element cannot be edited Content
inherit -----Inherit the contenteditable attribute of the parent element
When it is an empty string, the effect is the same as true.
When the contenteditable status of an element is true (the contenteditable attribute is an empty string, or is true, or is inherit and its parent element status is true), it means that the element is editable. Otherwise, the element is not editable.

document.body.contentEditable=true; You can modify the published website



    
        
        contentEditable属性
    

contentEditable属性

Hello contentEditable
Copy after login

1.3、hidden

The hidden attribute is used to hide the element. Once this attribute is used, the element will not be displayed in the browser
2 Boolean values ​​
true specifies that the element is visible.
false specifies that the element is invisible.

        
Copy after login

In order to be compatible with some browsers (IE8) that do not support this attribute, you can add the following style to CSS:

*[hidden]{
   display: none;
}
Copy after login
var p1=document.querySelector("body #p1");
p1.innerHTML+=" +++";
Copy after login

1.4, draggable

Specifies whether the element can be dragged
3 enumeration values
true specifies whether the element is draggable.
false specifies that the element is not draggable.
auto uses the browser's default features.

Example:



    
        
            
        
        
        
    

Copy after login

Run result:


    
    
    Document

Copy after login

##1.5, data- *

data-*attribute allows users to store data in the form of customized attributes


Value:
getAttribute('data-order-amount')
dataset.orderAmount
The data() method in jQuery can also be accessed

Example of using jQuery and javascript to add and obtain data attributes:


    
        
        data-*
        
    

data-*

Copy after login

Running effect:

1.6, placeholder attribute

This is a very practical attribute. There is no need to use JS to realize the click to clear the initial value of the form. Browser support is also pretty good. In addition to Firefox, other standard browsers can support it well


            

Copy after login

1.7, requiredRequired attribute

The constraint table unit must enter a value before submitting.

            

Copy after login

1.8, pattern regular attribute

Constrains the value entered by the user to match the regular expression.

            

请输入a-zA-Z0-9且长度6-16位的字符

Copy after login

1.9, autofocus automatic focus attribute
            

Copy after login

Let the specified form element get focus.

1.10. autocomplete attribute

When the autocomplete function is set on a form element, the information entered by the user will be recorded. Content, double-clicking the form element will display historical input.

该属性默认是打开的。

1.11、novalidate不验证属性

novalidate 属性规定在提交表单时不应该验证 form 或 input 域。

Copy after login

1.12、multiple多选属性

multiple 属性规定输入域中可选择多个内容,如:email 和 file

            

Copy after login



    
        
        HTML5新的表单元素
    

HTML5新的表单元素

请输入a-zA-Z0-9且长度6-16位的字符

Copy after login

推荐教程:html视频教程

The above is the detailed content of Does html5 have new attributes?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!