当前位置:网站首页>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
边栏推荐
- Find the largest of 3 strings (no more than 20 characters per string).
- 数论求a^b(a,b为1e12级别)的因子之和
- input元素添加监听事件
- Flink SQL实现流批一体
- 网赚APP资源下载类网站源码
- ATSS(CVPR2020)
- CGM优化血糖监测管理——移宇科技亮相四川省国际医学交流促进会
- Brief description of CPU
- Positioning of high precision welding manipulator
- C outputs a two-dimensional array with the following characteristics.
猜你喜欢
青苹果影视系统源码 影视聚合 影视导航 影视点播网站源码
Description of the abnormity that the key frame is getting closer and closer in the operation of orb slam
mysql查询字符串类型的字段使用数字类型查询时问题
跨域配置报错: When allowCredentials is true, allowedOrigins cannot contain the special value “*“
PyQt5开发之QTableWidget表头自定义与美化(附源代码下载)
Listed on the Shenzhen Stock Exchange: the market value is 5.2 billion yuan. Lu is the East and his daughter is American
Samsung, March to the west again
WordPress love navigation theme 1.1.3 simple atmosphere website navigation source code website navigation source code
The simple problem of leetcode is to calculate the numerical sum of strings
校园转转二手市场源码下载
随机推荐
The simple problem of leetcode is to calculate the numerical sum of strings
Positioning of high precision welding manipulator
欧圣电气深交所上市:市值52亿 陆为东父女为美国籍
LeetCode-199-二叉树的右视图
2022.4.11-4.17 AI行业周刊(第93期):AI行业的困局
An article understands variable lifting
ASAN 极简原理
LeetCode简单题之三除数
监控智能回放是什么,如何使用智能回放查询录像
LeetCode简单题之计算字符串的数字和
怎么读书读论文
QFileDialog 选择多个文件或文件夹
Why are there 1px problems? How?
微信小程序 catchtap=“toDetail“ 事件问题
网赚APP资源下载类网站源码
Qtablewidget header customization and beautification developed by pyqt5 (with source code download)
[effective go Chinese translation] part I
QT compilation qtxlsx Library
ansible自動化運維詳解(一)ansible的安裝部署、參數使用、清單管理、配置文件參數及用戶級ansible操作環境構建
5.6 综合案例-RTU-