1、左侧菜单栏
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>left menu</title>
<style>
.menu{
height: 300px;
width: 30%;
background: darkseagreen;
float: left;
}
.content{
height: 300px;
width: 70%;
background: coral;
float: left;
}
.title{
background: darksalmon;
color: black;
font-size: larger;
}
.hide{
display: none;
}
</style>
</head>
<body>
<div>
<div class="menu">
<div class="item">
<div class="title">菜单一</div>
<div class="con hide">
<div>111</div>
<div>111</div>
<div>111</div>
</div>
</div>
<div class="item">
<div class="title">菜单二</div>
<div class="con hide">
<div>222</div>
<div>222</div>
<div>222</div>
</div>
</div>
<div class="item">
<div class="title">菜单三</div>
<div class="con hide">
<div>333</div>
<div>333</div>
<div>333</div>
</div>
</div>
</div>
<div class="content"></div>
</div>
<script src="jquery-3.5.1.js"></script>
<script>
$(".item .title").click(function () {
$(this).next().removeClass("hide").parent().siblings().children(".con").addClass("hide")
})
</script>
</body>
</html>
2、tab切换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>tab切换</title>
<style>
*{
margin: 0px;
padding: 0px;
}
.outer{
margin: auto;
width: 40%;
}
.menu{
background: darkseagreen;
line-height: 40px;
border: solid 1px black;
}
.content{
background: darksalmon;
border: solid 1px black;
height: 200px;
}
.hide{
display: none;
}
li{
display: inline-block;
}
.current{
color: gold;
background: gray;
}
</style>
</head>
<body>
<div class="outer">
<div class="menu">
<ul>
<li xxx="c1" class="current" onclick="tab(this)">菜单一</li>
<li xxx="c2" onclick="tab(this)">菜单二</li>
<li xxx="c3" onclick="tab(this)">菜单三</li>
</ul>
</div>
<div class="content">
<div id="c1">内容一</div>
<div id="c2" class="hide">内容二</div>
<div id="c3" class="hide">内容三</div>
</div>
</div>
<script src="jquery-3.5.1.js"></script>
<script>
function tab(self) {
var index=$(self).attr("xxx")
$(self).addClass("current").siblings().removeClass("current")
$("#"+index).removeClass("hide").siblings().addClass("hide")
}
</script>
</body>
</html>
3、checkbox正反选
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<button onclick="select('all')">全选</button>
<button onclick="select('cancel')">取消</button>
<button onclick="select('reverse')">反选</button>
<!--相同函数名通过传递不同参数来选择不同操作-->
<table border="1" id="Table">
<tr>
<td><input type="checkbox"></td>
<td>111</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>222</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>333</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>444</td>
</tr>
</table>
<script src="jquery-3.5.1.js"></script>
<script>
function select(choice) {
if(choice=="all"){
$("table :checkbox").prop("checked",true)
}
else if (choice=="cancel"){
$("table :checkbox").prop("checked",false)
}
else if(choice=="reverse"){
$("table :checkbox").each(function () {
$(this).prop("checked",!$(this).prop("checked"))
})
}
}
</script>
</body>
</html>
4、模态对话框
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>模态对话框</title>
<style>
.back{
background: burlywood;
height: 2000px;
}
.shade{
background: aquamarine;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0.5;
}
.model{
position: fixed;
background: gold;
top: 50%;
left: 50%;
width: 200px;
height: 200px;
margin-left: -100px;
margin-top: -100px;
}
.hide{
display: none;
}
</style>
</head>
<body>
<div class="back">
<input type="button" value="点击" onclick="action1(this)">
</div>
<div class="shade hide"></div>
<div class="model hide">
<input type="button" value="取消" onclick="action2(this)">
</div>
<script src="jquery-3.5.1.js"></script>
<script>
function action1(self) {
$(self).parent().siblings().removeClass("hide")
}
function action2(self) {
$(self).parent().addClass("hide").prev().addClass("hide")
}
</script>
</body>
</html>
5、复制样式条
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>复制样式条</title>
</head>
<body>
<div>
<div class="item">
<input type="button" value="+" onclick="add(this)">
<input type="text">
</div>
</div>
<script src="jquery-3.5.1.js"></script>
<script>
function add(self) {
var $clone_obj=$(self).parent().clone();
$clone_obj.children(":button").val("-").attr("onclick","remove(this)");
($(self)).parent().parent().append($clone_obj);
}
function remove(self) {
$(self).parent().remove()
}
</script>
</body>
</html>
6、返回顶部
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>返回顶部</title>
<style>
body{
margin: 0px;
}
.div1{
background: darkgreen;
overflow: auto;
width: 300px;
}
.div2{
background: burlywood;
}
.div3{
background: darkseagreen;
}
.div{
height: 500px;
}
.returnTop{
width: 100px;
height: 100px;
background: gold;
text-align: center;
line-height: 100px;
right: 0;
bottom: 0;
position: fixed;
}
.hide{
display: none;
}
</style>
</head>
<body>
<div>
<div class="div1 div">
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
<div>hello</div>
</div>
<div class="div2 div"></div>
<div class="div3 div"></div>
<div class="returnTop hide" onclick="returnTop()">返回顶部</div>
</div>
<script src="jquery-3.5.1.js"></script>
<script>
window.onscroll=function () {
var $current=$(window).scrollTop()
if($current>100)
{
$(".returnTop").removeClass("hide")
}
else {
$(".returnTop").addClass("hide")
}
}
function returnTop() {
$(window).scrollTop(0)
}
</script>
</body>
</html>