javascript - 计算每次按钮单击并在输入类型号上显示
问题描述
我有一个功能,每次单击它时,我的按钮都会添加一个表格行。我的目标是,如何在输入类型 =“数字”中显示按钮单击的值?我的输入类型的值应该从“1”开始,每次单击按钮时,递增1。提前谢谢你。
HTML:
<button type="button" id="clickCount" onClick="clickMe" value="click me"></button>
<input type="number" id="showMe" value="1"> // the value of my button clicks should be displayed here
解决方案
用这个:
document.getElementById("clickCount").addEventListener("click", function() {
document.getElementById("showMe").value++;
})
<input type="number" id="showMe" value="1">
<button type="button" id="clickCount">Click Me</button>
推荐阅读
- python - 在数据点上绘制半径并计算该半径中的其他点
- c# - c# 根据另一个列表删除自定义列表中的项目
- javascript - 在 Java 中映射 JSON 对象
- javascript - 使用 getUserMedia 访问音频输入
- drupal - 通过功能(uuid_features)导出和导入词汇术语
- monaco-editor - 摩纳哥编辑器断点功能
- arrays - 可比较的扩展有效,但结果不佳
- php - 如何在mysql中保存日期和时间?
- docker - Windows Server 容器 - 无法访问容器主机端口
- javascript - 外部 js 文件不会运行 & css 100% 在钛 appcelerator 中的属性