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

Lainiao introduces javascript onclick event_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:21:231233browse

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>

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

Statement:
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