学了一点jQuery的东西感觉今后做网站的时候一定会用到的知识点:
1、自适应高度和宽度
2、加载项的实现onload()
3、添加先关的属性addClass
jQuery简单的使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<html>
<head>
<title>jquery</title>
<meta charset="utf-8"/>
<script src="jQuery/jquery-1.10.2.min.js"></script>
<style>
*{
margin:0;
padding:0;
}
html,body{
width:100%;
height:100%;
}
#div_top{
width:100%;
height:120px;
border:1px solid #555;
}
#div_content{
width:100%;
}
#div_left{
width:100px;
height:100%;
background:pink;
float:left;
}
#div_main{
height:100%;
background:green;
float:left;
}
#div_right{
width:80px;
height:100%;
background:red;
float:left;
}
#div_foot{
width:100%;
height:50px;
border:1px solid #555;
clear:both;
}
.show{
background:yellow !important;
}
</style>
<script>
/*判断中间部分的高度*/
function set_height(){
var a =$("body").css("height");
var b=$("#div_top").css("height");
var c=$("#div_foot").css("height");
var d=parseInt(a)-parseInt(b)-parseInt(c);
$("#div_content").css("height",d+"px");
}
/*判断中间部分的宽度*/
function set_width(){
var a =$("body").css("width");
var b=$("#div_left").css("width");
var c=$("#div_right").css("width");
var d=parseInt(a)-parseInt(b)-parseInt(c);
$("#div_main").css("width",d+"px");
}
$(document).ready(function(e){
set_width();
set_height();
$("#to_main").click(function(e){
/*这部分显示的是gradeList.htm里的#divGrade*/
$("#div_main").load("gradeList.htm");
/*添加一个class,给其另一个属性*/
$("#div_main").addClass("show");
})
})
$(window).resize(function(e){
set_width();
set_height();
})
</script>
</head>
<body>
<!--头部-->
<div id="div_top">
logo and nav
</div>
<!--中间-->
<div id="div_content">
<div id="div_left">content里的左栏
<a href="#" id="to_main">点击显示main里的内容</a>
</div>
<div id="div_main">content里的中间栏</div>
<div id="div_right">content里的右栏</div>
</div>
<!--底部-->
<div id="div_foot">
底部部分
</div>
</body>
</html>