The difference between get event in ff and IE

Source: Internet
Author: User

Ff and IE use different methods to obtain events:

Ie uses window. event, while FF directly uses the parameter event,

<HTML>
<Head>
<Title> IE and Firefox events </title>
</Head>
<SCRIPT type = "text/JavaScript">
Document. onkeydown = function (Event)
{
VaR event = event? Event: window. event;
If (event. keycode = 13)
{
VaR BTN = Document. getelementbyid ("btnlogin ");
BTN. Focus ();
BTN. onclick ();
}
};
</SCRIPT>

<Body>
<Input type = "button" name = "btnlogin" value = "login" onclick = "Return button#onclick () "tabindex =" 3 "id =" btnlogin "class =" button "style =" margin-top: 8px "/>
<Input name = "tbusername" type = "text" id = "tbusername" runat = "server"/>
</Body>
</Html>

 

 

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> how to obtain the event trigger source (compatible with IE and Firefox) </title>
<Meta name = "generator" content = "editplus"/>
<Meta name = "author" content = ""/>
<Meta name = "keywords" content = ""/>
<Meta name = "Description" content = ""/>
<SCRIPT type = "text/JavaScript">
Function clickme (E)
{
VaR src = e.tar GET | window. event. srcelement;
Alert (SRC. innerhtml );
}
Function clickme2 ()
{
VaR E = arguments [0] | window. event;
VaR src = E. srcelement | e.tar get; // SRC is the trigger source of the event.

Alert (SRC. innerhtml );
}
</SCRIPT>
</Head>

<Body>
<Button onclick = "clickme (event)"> test </button>
<Button onclick = "clickme2 (event)"> Test 2 </button>

</Body>
</Html>

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.