JavaScript DHTML/Event onMethod/onClick
Содержание
Add document onclick event handler
<source lang="html4strict">
<html> <head> <title>W3C DOM Event Propagation</title> <script type="text/javascript"> function init() {
document.onclick = docEvent;
} function docEvent(evt) {
alert("Document level .");
} </script> </head> <body onload="init()"> </body> </html>
</source>
Anchor onclick event
<source lang="html4strict">
<html> <head> <title>Onclick</title> <script type="text/javascript"> function handleclick() {
document.write("Clicked"); return false;
} </script> </head> <body>
<a href="#" onclick="return handleclick();">Click Here</a>
</body> </html>
</source>
"onClick" Example
<source lang="html4strict">
<html> <body> <input type="text"
name="textfield" onclick="alert("You clicked an input text field")" value="Click me">
</body> </html>
</source>
Put all your JavaScript statement in onclick clause
<source lang="html4strict">
<html> <head> <title>A Simple Page</title> </head> <body>
Click here to specify quantity
</body> </html>
</source>
Running a Script from User Action
<source lang="html4strict">
<html> <head> <title>An onclick script</title> <script type="text/javascript"> function alertUser() {
document.write("Hi!");
} </script> </head> <body> Here is some body text. <form> <input type="text" name="entry"> <input type="button" name="oneButton" value="Press Me!" onclick="alertUser()"> </form> </body> </html>
</source>