Home > Web Front-end > JS Tutorial > Lainiao introduces javascript onclick event_javascript skills

Lainiao introduces javascript onclick event_javascript skills

WBOY
Release: 2016-05-16 15:21:23
Original
1286 people have browsed it

Definition and usage of onclick event:

This event will be triggered when the object is clicked.

Browser support:

1.IE browser supports this event.
2. Firefox browser supports this event.
3. Opera browser supports this event.
4. Google Chrome supports this event.
5.Safria browser supports this event.

Example code:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8"/>
<meta name="author" content="http://www.jb51.net/" />
<title>脚本之家</title>
<style type="text/css">
div{
width:100px;
height:100px;
background-color:red;
}
</style>
<script type="text/javascript">
window.onload=function(){
var mydiv=document.getElementById("mydiv");
mydiv.onclick=function(){
mydiv.style.backgroundColor="green";
}
}
</script>
</head>
<body>
<div id="mydiv"></div>
</body>
</html>
Copy after login

The above content gives you a brief introduction to the javascript onclick event. I hope it will be helpful to you.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template