当前位置:网站首页>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>
边栏推荐
- Type of data in energy dashboard
- 成为优秀的TS体操高手 之 TS 类型体操前置知识储备
- octomap averageNodeColor函数说明
- 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
- Leetcode question brushing record | 203_ Remove linked list elements
- Document 2 Feb 12 16:54
- PHP - Common magic method (nanny level teaching)
- Nft智能合约发行,盲盒,公开发售技术实战--合约篇
- On why we should program for all
- 洛谷P1836 数页码 题解
猜你喜欢
opencv学习笔记八--答题卡识别
A Closer Look at How Fine-tuning Changes BERT
[cf gym101196-i] waif until dark network maximum flow
TS 类型体操 之 循环中的键值判断,as 关键字使用
21. Delete data
"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
Description of octomap averagenodecolor function
Google可能在春节后回归中国市场。
MEX有关的学习
[nonlinear control theory]9_ A series of lectures on nonlinear control theory
随机推荐
Database addition, deletion, modification and query
Launch APS system to break the problem of decoupling material procurement plan from production practice
[Yugong series] February 2022 U3D full stack class 011 unity section 1 mind map
(lightoj - 1410) consistent verbs (thinking)
[非线性控制理论]9_非线性控制理论串讲
A Closer Look at How Fine-tuning Changes BERT
数据治理:微服务架构下的数据治理
It's hard to find a job when the industry is in recession
shu mei pai
08- [istio] istio gateway, virtual service and the relationship between them
"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
TS 体操 &(交叉运算) 和 接口的继承的区别
Interview Reply of Zhuhai Jinshan
Apache middleware vulnerability recurrence
Linked list interview questions (Graphic explanation)
"Designer universe" APEC design +: the list of winners of the Paris Design Award in France was recently announced. The winners of "Changsha world center Damei mansion" were awarded by the national eco
[count] [combined number] value series
opencv学习笔记八--答题卡识别
[redis] Introduction to NoSQL database and redis
How to prevent Association in cross-border e-commerce multi account operations?