Javascript basic tutorial events
Let’s look at the following common events

onchange change event
Instance, code As shown below, when lowercase letters are entered in the text box, the mouse leaves the text box and changes to uppercase letters
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>事件</title>
<script type="text/javascript">
function cha(){
var x=document.getElementById("name");
x.value=x.value.toUpperCase();
}
</script>
</head>
<body>
请输入:<input type="text" id="name" onchange="cha()">
</body>
</html>onclick click event
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>事件</title>
<script type="text/javascript">
function cl(){
alert("php中文网");
}
</script>
</head>
<body>
<input type="button" value="点击" onclick="cl()">
</body>
</html>onmouseover and onmouseout events
Instance, let’s make an example, put the mouse on it, it will appear, welcome When the mouse leaves the php Chinese website, the text becomes php Chinese website
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>事件</title>
<style type="text/css">
#dv{
width:200px;height:200px;border:1px solid #f60;background-color: red;
text-align: center;line-height:200px;
}
</style>
</head>
<body>
<div id="dv" onmouseover="over(this)" onmouseout="out(this)"></div>
<script type="text/javascript">
function over(obj){
obj.innerHTML = "欢迎来到php中文网"; //鼠标放上去时
}
function out(obj){
obj.innerHTML = "php中文网"; // 鼠标离开后
}
</script>
</body>
</html>##onkeydown keyboard event
Now let’s do an example. In the text box, we press the keyboard and a prompt window will pop up<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>事件</title>
<script type="text/javascript">
function onkey(){
alert("您已触发键盘事件");
}
</script>
</head>
<body>
键盘事件:<input type="text" onkeydown="onkey()">
</body>
</html>onload Loading event
Let’s write an example below:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>事件</title>
<script type="text/javascript">
function checkCookies(){
if (navigator.cookieEnabled==true){
alert("Cookies 可用")
}else{
alert("Cookies 不可用")
}
}
</script>
</head>
<body onload="checkCookies()">
php 中文网
</body>
</html>
new file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>事件</title>
<script type="text/javascript">
function cha(){
var x=document.getElementById("name");
x.value=x.value.toUpperCase();
}
</script>
</head>
<body>
请输入:<input type="text" id="name" onchange="cha()">
</body>
</html>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















