觸發(fā) onclick
屬性事件當(dāng)單擊元素上的鼠標(biāo)按鈕時(shí)。
沒(méi)有。
<element onclick="script or Javascript function name">
所有HTML元素,EXCEPT:
<base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, <title>
onclick |
Yes | Yes | Yes | Yes | Yes |
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Click me</button>
<script>
function myFunction() {
console.log("clicked");
}
</script>
</body>
</html>
下面的代碼顯示了如何處理鼠標(biāo)點(diǎn)擊事件。
<html>
<head>
<script language="JavaScript">
function addunderline() {
head1.style.textDecoration = "underline"
}
function removeunderline() {
head1.style.textDecoration = "none"
}
function addoverline() {
head1.style.textDecoration = "overline"
}
function addlinethrough() {
head1.style.textDecoration = "line-through"
}
</script>
</head>
<body>
<h1 id="head1"
onMouseover="addunderline()"
onMouseout="removeunderline()"
onClick="addoverline()"
ondblclick="addlinethrough()">Welcome to this page!</h1>
<P>A lot of interesting text goes here!</p>
</body>
</html>
更多建議: