JavaScript IE fireEvent method details

  • 2020-03-29 23:54:24
  • OfStack

A fireEvent method is provided in IE, which as the name implies means to trigger an event to happen. At first I thought I was going to use onclick(), but recently I found out when I was writing a javascript primer PPT that I was too self-righteous! It seems that there are still a lot of javascript details to master!

Now document the use of the fireEvent method in detail according to your own summary. FireEvent is to provide a method of IE, MSDN documents address: http://msdn.microsoft.com/en-us/library/ms536423 (v = versus 85). Aspx

The onclick ()
Let's look at the first instance code:

< Ul onclick = "alert (event) srcElement) innerHTML); '>
< Li id = 'id1' > I am one. < / li>
< Li id = 'id2 > I am two. < / li>
< Li id = 'id3 > I am three. < / li>
< / ul>
< Button onclick = 'document. GetElementById (" id1 "). The onclick (); '> Click me! < / button>

Suppose we change the above code to:

< Ul onclick = "alert (event) srcElement) innerHTML); '>
< Li id = 'id1' onclick = 'alert (1); '> I am one. < / li>
< Li id = 'id2 > I am two. < / li>
< Li id = 'id3 > I am three. < / li>
< / ul>
< Button onclick = 'document. GetElementById (" id1 "). The onclick (); '> Click me! < / button>

At this point, clicking on the button triggers the onclick event, but ul's onclick does not, which indicates that dom.onclick () does not bubble.

FireEvent ()
Let's see if fireEvent is the same as the onclick() trigger event. Look at the following code:

< Ul onclick = "alert (event) srcElement) innerHTML); '>
< Li id = 'id1' > I am one. < / li>
< Li id = 'id2 > I am two. < / li>
< Li id = 'id3 > I am three. < / li>
< / ul>
< Button onclick = 'document. GetElementById (" id1 "). The fireEvent (" onclick ")' > FireEvent! < / button>

Summarize the differences between fireEvent and onclick
As you can see from the above example, DOM's fireEvent and onclick (this is just a delegate) differ in the following ways:

< Ul onclick = "alert (event) srcElement) innerHTML); '>
< Li id = 'id1' onclick = 'alert (1); '> I am one. < / li>
< Li id = 'id2 > I am two. < / li>
< Li id = 'id3 > I am three. < / li>
< / ul>
< Button onclick = 'document. GetElementById (" id1 "). The onclick (); '> Click me! < / button>
< Button onclick = 'document. GetElementById (" id1 "). The fireEvent (" onclick ")' > FireEvent! < / button>


Related articles: