jQuery事件详解

2020-05-23 06:16:23易采站长站整理

一.window事件


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script type="text/javascript" src="js/jQuery1.11.1.js"></script>
<script type="text/javascript">
$(function(){
alert("1");
})
window.onload=function
</script>
</head>
<body>
<h1>New Web Project Page</h1>
</body>
</html>

二.鼠标事件(光棒效果)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script type="text/javascript" src="js/jQuery1.11.1.js"></script>
<script type="text/javascript">
$(function(){
var aa=$("li");
aa.mouseover(function(){
$(this).css("background","blue")
})
aa.mouseout(function(){
$(this).css("background","")
})
})
</script>
</head>
<body>
<ul>
<li>呵呵</li>
<li>嘻嘻</li>
<li>哈哈</li>
</ul>
</body>
</html>

三.键盘事件


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
<script type="text/javascript" src="js/jQuery1.11.1.js"></script>
<script type="text/javascript">
$(function(){
$("input").keyup(function(event){
var co=event.keyCode;
alert(co);
})
})
</script>
</head>
<body>
<h1>呵呵</h1>
<input />
</body>
</html>

四.表单事件


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>