<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
</head>
<body>
<p>返回相邻的同胞元素</p>
<div class="query-set" onclick="rptOpenSelectWindow(this)">
第一个 <i class="icon-caret-down"/>
</div>
<div class="query-field" style="background-color:red">
第二个 <ul id="rpt_setting_2"/>
</div>
<script>
function rptOpenSelectWindow(_this) {
var w = _this.nextSibling;
if (w.style.display != 'block') {
w.style.display = 'block';
} else {
w.style.display = 'none';
}
}
</script>
</body>
</html>
点击第一个会显示 或者隐藏

本文档展示了一个使用jQuery实现的简单交互示例,通过点击带有特定类名的div元素,可以显示或隐藏其相邻的兄弟元素。此功能适用于创建可折叠的菜单或其他需要隐藏和显示内容的场景。
1288

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



