Home>Article>Web Front-end> Cleverly add onload events to div and p tags

Cleverly add onload events to div and p tags

angryTom
angryTom forward
2019-12-16 17:23:07 4711browse

Cleverly add onload events to div and p tags

How to add onload event to div and p?

##Premise

In fact, there are only 6c04bd5ca3fcae76e30b72ad730ca86d, 04a0d55efbbfd646a993fbc01f262c57, d5ba1642137c3f32f4f4493ae923989c, a1f02c36ba31691bcfe87b2722de723b, 2cdf5bf648cf2f33323966d7f58a7f3f, < ;script>, c9ccee2e6ea535a969eb3f532ad9fe89 only these tags have onload events, while div, p and other tags do not.

But what if we still want to do something when the div is appended to the DOM? Some people will say that it is enough to just add it after the code that appends to the DOM, but this will have to be written after each append place one by one, which is very troublesome.

For example

我有一只小毛驴,我从来也不骑。

Suppose I want to pop up the "I am a little donkey" prompt box after the above content is loaded.

Borrowing Flowers to Offer Buddha

I still want to use onload event processing. We also know which tags are supported, so we can change the code to:

我有一只小毛驴,我从来也不骑。

In this way, by borrowing the style tag, as long as the div is appended to the DOM, the onload event can be simulated to be triggered.

This article comes from the

js tutorialcolumn, welcome to learn!

The above is the detailed content of Cleverly add onload events to div and p tags. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete