JavaScript mouse click event (onclick)
onclick is a mouse click event, which occurs when the mouse is clicked on the web page. At the same time, the program block called by the onclick event will be executed, usually used with buttons.
Let’s see an example
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> function fun1(){ window.alert("欢迎来到php.cn") } function fun2(){ window.alert("你看,你还是点了我") } </script> </head> <body> <form> <input name="点我看看" type="button" value="点我看看" onclick="fun1()"/> <p onclick="fun2()">不要点我</p> </form> </body> </html>
You can try adding onclick events to other tags