JavaScript鼠標(biāo)單擊事件(onclick)
onclick是鼠標(biāo)單擊事件,當(dāng)在網(wǎng)頁(yè)上單擊鼠標(biāo)時(shí),就會(huì)發(fā)生該事件。同時(shí)onclick事件調(diào)用的程序塊就會(huì)被執(zhí)行,通常與按鈕一起使用。
來看個(gè)例子
<!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("你看,你還是點(diǎn)了我") } </script> </head> <body> <form> <input name="點(diǎn)我看看" type="button" value="點(diǎn)我看看" onclick="fun1()"/> <p onclick="fun2()">不要點(diǎn)我</p> </form> </body> </html>
大家可以嘗試在其它標(biāo)簽上加上onclick事件