引入库

<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script>
bind绑定多个事件到一块
$(document).ready(function(){
$("button").bind({
click:function(){$("p").slideToggle();},
mouseover:function(){$("body").css("background-color","red");},
mouseout:function(){$("body").css("background-color","#FFFFFF");}
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button>请点击这里</button>
</body>
 
 
focus聚焦 blur失焦事件 $("input")代表所有的input标签元素
<script>
$(document).ready(function(){
$("input").focus(function(){
$("input").css("background-color","green");
});
$("input").blur(function(){
$("input").css("background-color","red");
});
});
</script>
</head>
<body>
Enter your name: <input type="text" />
</body>
 
//值改变change事件
<script>
$(document).ready(function(){
$(".field").change(function(){
$(this).css("background-color","red");
});
});
</script>
</head>
<body>
Enter your name: <input class="field" type="text" />
<p>Car:
<select class="field" name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
</select>
</p>
</body>
<script>
$(document).ready(function(){
$(".field").change(function(){
$(this).css("background-color","#FFFFCC");
});
$("button").click(function(){
$("input").change();//change事件可以定义好后再被激活
});
});
</script>
</head>
<body>
<button>激活文本域的 change 事件</button>
<p>Enter your name: <input class="field" type="text" /></p>
</body>