当前位置:网站首页>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>
边栏推荐
- Database addition, deletion, modification and query
- How to prevent Association in cross-border e-commerce multi account operations?
- WebRTC系列-H.264预估码率计算
- Oracle time display adjustment
- MES, APS and ERP are essential to realize fine production
- [redis] Introduction to NoSQL database and redis
- Pre knowledge reserve of TS type gymnastics to become an excellent TS gymnastics master
- Onie supports pice hard disk
- 649. Dota2 Senate
- Le chemin du navigateur Edge obtient
猜你喜欢
Machine learning - decision tree
22. Empty the table
"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
Nft智能合约发行,盲盒,公开发售技术实战--合约篇
Document 2 Feb 12 16:54
octomap averageNodeColor函数说明
Qualitative risk analysis of Oracle project management system
Simulation of holographic interferogram and phase reconstruction of Fourier transform based on MATLAB
Mex related learning
"Designer universe" Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers | national economic and Informa
随机推荐
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
数据治理:数据质量篇
Helm install Minio
Understanding of law of large numbers and central limit theorem
What are the ways to download network pictures with PHP
数字经济时代,如何保障安全?
Type of data in energy dashboard
Binary tree creation & traversal
Le chemin du navigateur Edge obtient
Database addition, deletion, modification and query
[nonlinear control theory]9_ A series of lectures on nonlinear control theory
你想知道的ArrayList知识都在这
解决方案:智慧工地智能巡檢方案視頻監控系統
Iterator Foundation
数据治理:元数据管理篇
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
Rust language - receive command line parameter instances
Get the path of edge browser
DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist
xpath中的position()函数使用