一.绑定事件
$(selector).eventType(callBack);
二.源码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>绑定事件</title>
<script src="./js/jQuery.js"></script>
<style>
*{
margin: 0;
padding: 0;
}
div{
width: 250px;
height: 250px;
background:grey;
margin-top: 10px;
}
</style>
</head>
<body>
<div></div>
<div></div>
</body>
</html>
<script>
//单机事件
$("div:eq(0)").click(function(event){
//事件处理函数
$("div:eq(0)").css({"background":"cyan"});
});
//鼠标移上
$("div:eq(1)").mouseenter(function(){
$("div:eq(1)").css({'width':100,'height':100,'background':"green"});
});
//鼠标移除
$("div:eq(1)").mouseleave(function(){
$("div:eq(1)").css({"width":250,"height":250,"background":"black"});
});
</script>
三.效果图
篇章
上一篇:jQuery教程8-特效函数