当前位置:网站首页>JS select all and tab bar switching, simple comments
JS select all and tab bar switching, simple comments
2022-07-06 07:58:00 【MyDreamingCode】
1. js Future generations
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
table {
margin: 100px auto;
}
thead {
background-color: burlywood;
}
tbody {
background-color: pink;
}
</style>
</head>
<body>
<table border="1" cellspacing="0" cellpadding="10">
<thead>
<tr>
<td><input type="checkbox"></td>
<td> goods </td>
<td> Price </td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox"></td>
<td> Teddy bear </td>
<td>20</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td> Hamburger </td>
<td>25</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td> game </td>
<td>150</td>
</tr>
</tbody>
</table>
<script>
var chooseAll = document.querySelector('thead').querySelector('input');
var goodChoose = document.querySelector('tbody').querySelectorAll('input');
chooseAll.onclick = function() {
for(var i = 0; i < goodChoose.length; ++i) {
goodChoose[i].checked = this.checked;
}
}
for(var i = 0; i < goodChoose.length; i++) {
goodChoose[i].onclick = function() {
var flag = true;
for(var j = 0; j < goodChoose.length; j++) {
if(!goodChoose[j].checked) {
flag = false;
}
}
chooseAll.checked = flag;
}
}
</script>
</body>
</html>
2. Tab Bar Toggle
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
.wrap {
width: 180px;
margin: 100px auto;
border: 1px solid #000;
}
.content {
height: 100px;
background-color: steelblue;
border-top: 1px solid #000;
}
ul {
list-style: none;
cursor: pointer;
}
li {
float: left;
width: 60px;
text-align: center;
border-right: 1px solid #000;
box-sizing: border-box;
}
li:last-child {
border-right: 0;
}
.clearfix::after {
content: '';
display: block;
clear: both;
}
.bg {
background-color: tan;
}
.content div {
display: none;
}
</style>
</head>
<body>
<div class="wrap">
<div class="top">
<ul class="clearfix">
<li>Tab1</li>
<li>Tab2</li>
<li>Tab3</li>
</ul>
</div>
<div class="content">
<div style="display: block;"> This is a tab1 The content of </div>
<div> This is a tab2 The content of </div>
<div> This is a tab3 The content of </div>
</div>
</div>
<script>
var lis = document.querySelectorAll('li');
var divs = document.querySelector('.content').querySelectorAll('div');
for(var i = 0; i < lis.length; i++) {
lis[i].setAttribute('data-index',i);
lis[i].onclick = function() {
for(var j = 0; j < lis.length; j++) {
lis[j].className = '';
}
this.className = 'bg';
for(var k = 0; k < lis.length; k++) {
divs[k].style.display = 'none';
}
divs[this.dataset.index].style.display = 'block';
}
}
</script>
</body>
</html>
3. Simple comments
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
.wrap {
width: 300px;
margin: 100px auto;
}
ul {
list-style: none;
}
li {
border-bottom: 1px solid #ccc;
}
li a {
float: right;
}
</style>
</head>
<body>
<div class="wrap">
<textarea name="" id="" cols="30" rows="10"></textarea>
<button> Release </button>
<ul></ul>
</div>
<script>
var ul = document.querySelector('ul');
var btn = document.querySelector('button');
var txt = document.querySelector('textarea');
btn.onclick = function() {
if(txt.value == '') {
alert(' Please enter the content ');
return false;
}else {
var li = document.createElement('li');
li.innerHTML = txt.value + "<a href='javascript:;'> Delete </a>";
ul.insertBefore(li,ul.children[0]);
}
txt.value = '';
var a = document.querySelectorAll('a');
for(var i = 0; i < a.length; i++) {
a[i].onclick = function() {
ul.removeChild(this.parentNode);
}
}
}
</script>
</body>
</html>
边栏推荐
- DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist
- Apache middleware vulnerability recurrence
- 成为优秀的TS体操高手 之 TS 类型体操前置知识储备
- C # display the list control, select the file to obtain the file path and filter the file extension, and RichTextBox displays the data
- shu mei pai
- Helm install Minio
- Hackathon ifm
- Position() function in XPath uses
- WebRTC系列-H.264预估码率计算
- Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
猜你喜欢
数字经济时代,如何保障安全?
合规、高效,加快药企数字化转型,全新打造药企文档资源中心
Google may return to the Chinese market after the Spring Festival.
22. Empty the table
[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map
[t31zl intelligent video application processor data]
07- [istio] istio destinationrule (purpose rule)
Apache middleware vulnerability recurrence
让学指针变得更简单(三)
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
随机推荐
Redis list detailed explanation of character types yyds dry goods inventory
数据治理:主数据的3特征、4超越和3二八原则
解决方案:智慧工地智能巡檢方案視頻監控系統
Asia Pacific Financial Media | designer universe | Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers
"Friendship and righteousness" of the center for national economy and information technology: China's friendship wine - the "unparalleled loyalty and righteousness" of the solidarity group released th
It's hard to find a job when the industry is in recession
Circuit breaker: use of hystrix
flask返回文件下载
合规、高效,加快药企数字化转型,全新打造药企文档资源中心
Luogu p4127 [ahoi2009] similar distribution problem solution
P3047 [usaco12feb]nearby cows g (tree DP)
Generator Foundation
Pre knowledge reserve of TS type gymnastics to become an excellent TS gymnastics master
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
Go learning notes (3) basic types and statements (2)
Simulation of Michelson interferometer based on MATLAB
Understanding of law of large numbers and central limit theorem
Yu Xia looks at win system kernel -- message mechanism
【Redis】NoSQL数据库和redis简介
Rust language - receive command line parameter instances