JavaScript鼠标单击事件(onclick)

onclick是鼠标单击事件,当在网页上单击鼠标时,就会发生该事件。同时onclick事件调用的程序块就会被执行,通常与按钮一起使用。

来看个例子

<!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>

大家可以尝试在其它标签上加上onclick事件

继续学习
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!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>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
提交重置代码
图片放大关闭