JavaScript event binding method and compatible IE FF solution

Source: Internet
Author: User

Web page Special Effects event binding method and compatible IE FF solution

var t = document.getElementById ("Tab1");
T.onclick = function tst () {
Alert (")";
}

The second method

var TB = document.getElementById ("Tab1");
if (Window.addeventlistener) {//Mozilla, Netscape, Firefox
Td_value.addeventlistener (' Click ', alert (' One '), false);
Td_value.addeventlistener (' Click ', Alert (' '), false);
else {//IE
Td_value.attachevent (' onclick ', function () {alert (' 21 ');});
Td_value.attachevent (' onclick ', function () {alert (' 2 ' 2);});
} ]


JS event events in IE, FF compatibility issues


1, window.event

ie: there are window.event objects
FF: no Window.event object. You can pass an event object to a parameter of a function.
Such as:
The code is as follows:

<input type= "button" onmousemove= "Showdiv (event);" event does not need to be quoted
function Showdiv (event)
{
var event=window.event| | Event
Event.clientx;
Event.clienty;
}

JavaScript Event Binding issues


Child page HTML:
The code is as follows:

<input type= "checkbox" name= "Check" onclick= "Checkedbox (This)" value= "a"/>


Sub-page JS:
The code is as follows:

function Createioc (text,value) {
var o = document.createelement ("a");
O.id = value;
O.href = "#";
O.classname = "C";
O.style.border = "2px solid red";
O.style.width = "250px";
O.style.height = "30px";
O.style.display = "block";
o.innerhtml = "<table><tr><td>" + text + "</td><td></td></tr></table> ';
O.setattribute ("onclick", "Iocclick ()");
return o;
}
function Iocclick () {
Alert (' OK ');
}
function Checkedbox (box) {
Window.parent.document.getelementbyid ("Kdks_panel"). AppendChild (Createioc (' 1 ', ' 2 '));
}

Parent-HTML:
The code is as follows:

<div id= "Kdks_panel" ></div>

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.