当前位置:网站首页>DOM 学习之—添加+-按钮
DOM 学习之—添加+-按钮
2022-04-23 07:34:00 【beinlife】
<button οnclick="calc(this)">-</button>
<span>1</span>
<button οnclick="calc(this)">+</button>
</td>
function calc(btn){
//找到旁边的span:
//1、向上找td
var td=btn.parentNode;//向上爬树
//2、在td下找span
var span=td.getElementsByTagName("span")[0];//向下爬树
//3、取出span的数n
var num=span.innerHTML;
//4、如果btn是+,则n++,否则n--
btn.innerHTML=="+"?num++:num--;
//5、如果n==0,则改为1
num==0&&(num=1);
//6、将n放回span中
span.innerHTML=num;
}
版权声明
本文为[beinlife]所创,转载请带上原文链接,感谢
https://blog.csdn.net/beinlife/article/details/52926661
边栏推荐
猜你喜欢

LeetCode-199-二叉树的右视图

Positioning of high precision welding manipulator

社区团购小程序源码+界面diy+附近团长+供应商+拼团+菜谱+秒杀+预售+配送+直播

总线结构概述

Qt读写XML文件

CGM optimizes blood glucose monitoring and management -- Yiyu technology appears in Sichuan International Medical Exchange Promotion Association

vmware 搭建ES8的常见错误
![[learning] audio and video development from scratch (9) -- nuplayer](/img/62/20b0d80088181fb6ff1fe842500c0a.png)
[learning] audio and video development from scratch (9) -- nuplayer

Comparison of indoor positioning methods of several intelligent robots

Qtablewidget header customization and beautification developed by pyqt5 (with source code download)
随机推荐
js常用数组方法
华硕笔记本电脑重装系统后不能读取usb,不能上网
dried food! Point based: differentiable Poisson solver
Using qlst excel file
多目视觉SLAM
C language learning record -- use and analysis of string function (2)
LeetCode简单题之计算字符串的数字和
Compiling principle questions - with answers
使用JWT生成与解析Token
刨析——浏览器如何工作
There are some problems when using numeric type to query string type fields in MySQL
Find the largest of 3 strings (no more than 20 characters per string).
form表单 post提交 数据量大的问题
Multi vision slam
QFileDialog 选择多个文件或文件夹
stm32以及freertos 堆栈解析
colorui 解决底部导航遮挡内容问题
freertos学习02-队列 stream buffer message buffer
LeetCode中等题之旋转函数
一款拥有漂亮外表的Typecho简洁主题_Scarfskin 源码下载