当前位置:网站首页>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>边栏推荐
- [computer skills]
- Solution: intelligent site intelligent inspection scheme video monitoring system
- Pre knowledge reserve of TS type gymnastics to become an excellent TS gymnastics master
- 数据治理:数据质量篇
- Get the path of edge browser
- Le chemin du navigateur Edge obtient
- Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
- 2.10transfrom attribute
- Entity class design for calculating age based on birthday
- Machine learning - decision tree
猜你喜欢

Asia Pacific Financial Media | art cube of "designer universe": Guangzhou community designers achieve "great improvement" in urban quality | observation of stable strategy industry fund

Uibehavior, a comprehensive exploration of ugui source code

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

Description of octomap averagenodecolor function

Go learning notes (3) basic types and statements (2)

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
![[1. Delphi foundation] 1 Introduction to Delphi Programming](/img/14/272f7b537eedb0267a795dba78020d.jpg)
[1. Delphi foundation] 1 Introduction to Delphi Programming

Epoll and IO multiplexing of redis

Golang DNS 随便写写

TS 类型体操 之 循环中的键值判断,as 关键字使用
随机推荐
Understanding of law of large numbers and central limit theorem
PHP - Common magic method (nanny level teaching)
What are the ways to download network pictures with PHP
你想知道的ArrayList知识都在这
Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
TS 类型体操 之 循环中的键值判断,as 关键字使用
合规、高效,加快药企数字化转型,全新打造药企文档资源中心
Wireshark grabs packets to understand its word TCP segment
649. Dota2 Senate
Cf1036c class numbers solution
1015 reversible primes (20 points) prime d-ary
Luogu p4127 [ahoi2009] similar distribution problem solution
实现精细化生产, MES、APS、ERP必不可少
[1. Delphi foundation] 1 Introduction to Delphi Programming
Description of octomap averagenodecolor function
National economic information center "APEC industry +": economic data released at the night of the Spring Festival | observation of stable strategy industry fund
[Yugong series] creation of 009 unity object of U3D full stack class in February 2022
[非线性控制理论]9_非线性控制理论串讲
Golang DNS 随便写写
Le chemin du navigateur Edge obtient