First:Button.onclick = Function ("alert (' Hello ');");
The second type:Button.onclick = function () {alert ("Hello");
The third type:Button.onclick = Myalert;
function Myalert () {
Alert ("Hello");
}
The fourth kind:
This situation is more dynamic, more practical, but also can add more than one function (add the sequence of events is the order of execution), hehe
if (Window.addeventlistener) {//Mozilla, Netscape, Firefox
//element.addeventlistener (type,listener,usecapture );
Button.addeventlistener (' Click ', alert (' One '), false);
Button.addeventlistener (' Click ', Alert ('), false '),//execution order->
/else {//IE
button.attachevent (' OnClick ', function () {alert (') ';});
Button.attachevent (' onclick ', function () {alert (' 22 ');}); Execution Order->
}
Example Explanation:
Button.onclick = Function ("alert (');");
Button.onclick = Function ("alert (');");
Button.onclick = Function ("alert (' 33 ');"); If you write this, then only the last method will be executed
button.attachevent ("onclick", function () {alert (' a ');});
Button.attachevent ("onclick", function () {alert (' n ');});
Button.attachevent ("onclick", function () {alert (' 43 ');}); If you write this, three methods will be executed
//or, of course, you can write
Button.onclick = Function ("alert")
; Button.attachevent ("onclick", function () {alert (' ");});
Corresponds to the removal event
detachevent (' onclick ', func);//ie Use Delete event func
removeeventlistener (' click ', func); Delete event Func
The above JS modified onclick action four methods (recommended) is a small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.