Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the interfaces of 5 unknown HTML5?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

5 do not know what the interface of HTML5 is, I believe that many inexperienced people do not know what to do about this, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

When people see or say the word "HTML5", it is estimated that at least half of them will think that she is not only a sexy and charming beauty, but also a unicorn who can mess you up. Can you blame us developers?

We noticed that the basic Api stagnation has developed for such a long time (about 1999-2009) that it takes us a long time to deal with a basic additional function like "placeholder".

Although current mainstream browsers have implemented a lot of new HTML5 features, many developers simply don't notice these more concise and useful API.

Element.classList

This property has been released for several years, and with classList, we can manipulate the class property of the underlying css through JavaScript.

The code is as follows:

The code is as follows:

/ / use the classList attribute (Dom element, css class name)

Function toggleClassList (element,cName) {

/ / 1. ClassList API

/ / switch classes, remove if there is, add if not

If (element.classList.toggle) {

Element.classList.toggle (cName)

Return true

}

/ /! In fact, if this function toggleClassList is supported

/ / then the following code will not be executed. Here is only a demonstration. Please apply it flexibly.

/ / 2. ClassList API

/ / whether the class attribute of element contains the CSS class hide

Var hasHide = element.classList.contains (cName)

/ /

If (hasHide) {

/ / 3. ClassList API

/ / remove the hide class

Element.classList.remove (cName)

} else {

/ / 4. ClassList API

/ / add hide class

Element.classList.add (cName)

}

Return true

}

ContextMenu API

After testing, chrome28 doesn't work.

The new API,ContextMenu is an excellent interface: this interface allows you to easily add menu items to the browser's context menu (right-click menu), rather than overriding the browser's default right-click menu.

It is important to note that it is best to use the js script to create menu contextmenu dynamically, so as to avoid redundant HTML code if the JS script is disabled on the page.

The code is as follows:

The code is as follows:

Click this area to view the menu

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report