事件
.bind()方法,绑定一个事件:
$(document).ready(function(){
$('#switcher-large').bind('click',function(){
$('body').addClass('large');
});
});
.click事件:
$(document).ready(function(){
$('#switcher').click(function(){
$('body').removeClass();
});
});
.toggle方法:切换元素的可见状态
$(document).ready(function(){
$(".btn1").click(function(){
$("p").toggle();
});
});
.hover方法:接受两个函数参数,第一个函数会在鼠标指针进入被选择的元素时执行,而第二个函数会在指针离开该元素时触发
$('p').hover(function(){
(this).css("backgorund-color","yellow");
},function(){
(this).css("background-color","pink");
});
.stopPropagation()方法:阻止事件冒泡
.preventDefault()方法可以在触发默认操作之前终止事件(可用于提交表单期间对用户是否填写了必填字段进行检查)