1.window.onload和document.ready的区别
当执行多个windows.onload时,页面加载完毕后只会执行最后一个windows.onload
执行多个document.ready时,会按顺序执行多个document.ready.
2.事件绑定
bind()函数
bind(type[,data,],fn);
//案例:事件绑定完成闭合
<script type="text/javascript">
$(document).ready(function(){
$(".he").bind("mouseover",function(){
$(this).next().show();
});
$(".he").mouseout(function(){
$(this).next().hide();
});
});
</script>
3.合成事件
hover(over,out) 函数
当鼠标放上执行第一个函数,当鼠标离开,执行第二个函数
<script type="text/javascript">
$(document).ready(function(){
$(".he").hover(function(){
$(this).next().show();
$(this).addClass("green");
},function(){
$(this).next().hide();
$(this).removeClass("green");
})
});
</script>
toggle(fn1,fn2,fn3…)函数
点击了第一个匹配元素,则会触发第一个函数,再次点击会触发第二个,再点击会触发第三个…
<script type="text/javascript">
$(document).ready(function(){
$(".he").toggle(function(){
$(this).next().show();
$(this).addClass("green");
},function(){
$(this).next().hide();
$(this).removeClass("green");
})
});
</script>
4.移除事件
unbind(“click”) 移除点击事件
$("#i01").click(function(){
$(".he").unbind("click");
});