日期:2014-05-16  浏览次数:20377 次

ready和onload比较;可以在下面的script里面调用先前script;动态为元素添加事件;浮动广告;js添加删除tr

JQuery等js框架一般都提供一个ready事件,该事件是document对象的,类似onload 

onloadready哪个先执行?

1)  ready是在页面html代码全部加载完成后自动执行,也就是DOM树结构建立好后就执行

2)  load则是在页面所有资源加载完成后才执行。


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
 <script type="text/javascript" src="jquery/jquery-1.9.1.js"></script>
<script  type="text/javascript">
function allSelect(flag){
var allItem=document.getElementsByName("province");
for(var i=0;i<allItem.length;i++){
allItem[i].checked=flag;
}
}
function changeColor(){

//给大于0的奇数行修改背景色
$("#myTable tr:gt(0):odd").attr("bgColor","#00ff00");
$("#myTable tr:gt(0):even").attr("bgColor","#eeeeee");

$("#firstTr+tr").attr("bgColor","#ff0000");
}
function checkAllBox(flag){

$(":checkbox[name='email']").attr("checked",flag);


}
function test(){
alert("test");
}
function onButton(){
//:后面跟的是type的值,first表示第一个button,开启onclick功能
$(":button:first").on("click",test);

}
function offButton(){
//关闭click功能
$(":button:first").off("click");
}
function showImg(){//浮动广告