本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
jquery中能够实现元素高度变化的函数
1、height()函数
height() 方法可设置匹配元素的高度。
语法:
复制代码1
$(selector).height(length)
登录后复制
length 可选。规定元素的高度。如果没有规定长度单位,则使用默认的 px 单位。
示例:
复制代码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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("div").height(100);
});
});
</script>
<style type="text/css">
div {
height: 50px;
border: 1px solid red;
}
</style>
</head>
<body>
<div></div>
<br /><br />
<button>改变div元素的高度</button>
</body>
</html>
登录后复制
2、css()函数
css() 方法可设置匹配元素的样式属性。
语法:
复制代码1
$(selector).css(name,value)
登录后复制
示例:
复制代码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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("div").css("height","200px");
});
});
</script>
<style type="text/css">
div {
height: 50px;
border: 1px solid red;
}
</style>
</head>
<body>
<div></div>
<br /><br />
<button>改变div元素的高度</button>
</body>
</html>
登录后复制
相关教程推荐:jQuery视频教程
以上就是jquery中能够实现元素高度变化的是什么函数的详细内容,更多请关注靠谱客其它相关文章!
最后
以上就是殷勤煎饼最近收集整理的关于jquery中能够实现元素高度变化的是什么函数的全部内容,更多相关jquery中能够实现元素高度变化内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复