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