亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Javascript basic tutorial events

Let’s look at the following common events

nnn.png

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>
	請(qǐng)輸入:<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中文網(wǎng)");
		}
	</script>
</head>
<body>
	<input type="button" value="點(diǎn)擊" 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 = "歡迎來(lái)到php中文網(wǎng)"; //鼠標(biāo)放上去時(shí)
			}

			function out(obj){
				obj.innerHTML = "php中文網(wǎng)"; // 鼠標(biāo)離開(kāi)后
			}
	</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("您已觸發(fā)鍵盤(pán)事件");
		}
	</script>	
</head>
<body>
		鍵盤(pán)事件:<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 中文網(wǎng)
</body>
</html>



Continuing Learning
||
<!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> 請(qǐng)輸入:<input type="text" id="name" onchange="cha()"> </body> </html>
submitReset Code