1. event handler as the HTML property value
HTML code
<Input name = "btn" type = "button" id = "btn" value = "button" onclick = "alert ('mzwu. com');"/>
2. event handler as a JavaScript property
Webpage tutorial Network
HTML code
<Input name = "btn" type = "button" id = "btn" value = "button"/>
<Script language = "javascript">
Document. getElementById ("btn"). onclick = function () {alert ("mzwu.com ");}
</Script>
Note: The first method may mislead you to write it as document. getElementById ("btn "). onclick () = "alert ('mzwu. com '); ", this write is incorrect! In fact, the first method implicitly creates a function, which can be described using the following code, because it detects that the HTML attribute value is actually a function:
Webjx. Com
HTML code
<Input name = "btn" type = "button" id = "btn" value = "button" onclick = "alert (typeof (this. onclick);"/>
Webpage tutorial Network
The above Code uses a direct volume to create a function and changes it to the function () Statement:
HTML code
<Input name = "btn" type = "button" id = "btn" value = "button"/>
<Script language = "javascript">
Function e ()
{
Alert ("mzwu.com ");
}
Document. getElementById ("btn"). onclick = e;
</Script>
Webpage tutorial Network
Therefore, we can extend the third method.
Webjx. Com
3. Method 3
Webjx. Com
HTML code
<Input name = "btn" type = "button" id = "btn" value = "button"/>
<Script language = "javascript">
Function document. all. btn. onclick ()
{
Alert ("mzwu.com ");
}
</Script>
Note: such methods include function document. onclick () {}, but this method is only feasible in IE and FF tests, and then changed to function document. getElementById ("btn "). onclick () {} does not work in IE or FF. It is not difficult to explain the lack of identifiers, because the JavaScript identifiers do not allow dot numbers. document is used. getElementById ("btn "). the onclick identifier is obviously incorrect, but the document. all. btn. onclick is a bit confusing.