点击div显示隐藏div,并改变图标
了解到关于html对象“this”与jquery对象“$(this)”的使用
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="../js/jquery-2.1.1.min.js" ></script>
<script type="text/javascript" src="../js/bootstrap.min.js" ></script>
<link rel="stylesheet" href="../css/bootstrap.min.css" />
</head>
<body>
<div id="toggle">
用户信息<span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
</div>
<div id="content" style="display: none;">
<p>隐藏内容</p><p>隐藏内容</p>
</div>
</body>
<script type="text/javascript">
$(function() {
$("#toggle").click(function() {
var spanClass=$("#toggle").find("span").get(0);
var state =spanClass.className.indexOf('glyphicon-triangle-bottom') > -1;
$("#toggle").find("span").toggleClass('glyphicon-triangle-bottom', !state).toggleClass('glyphicon-triangle-top', state);
$("#content").slideToggle();
});
});
</script>
</html>
点击文字切换文字,并显示隐藏div
<script type="text/javascript">
$(function() {
$("#toggle").click(function() {
$(this).text($("#content").is(":hidden") ? "收起" : "展开");
$("#content").slideToggle();
});
});
</script>
402

被折叠的 条评论
为什么被折叠?



