我正在使用将数据提交到 MYSQL 数据库的 html 表单。我需要添加一个按钮,每次按下都会将文本框中的数字增加一个。我的代码如下所示:
<label for="htop">Top: </label>
<input type="button" name="decrease" value="-" /><input type="text" name="htop" value="0" />
<input type="button" name="increase" value="+" />
执行此操作的最佳方法是什么?
最佳答案
将脚本标签放在你的head元素中
<script>
function increaseBtnOnclick() {
document.getElementById("htop").value = Number(document.getElementById("htop").value) + 1;
}
</script>
<label for="htop">Top: </label>
<input type="button" name="decrease" value="-" /><input type="text" name="htop" value="0" id="htop"/>
<input type="button" name="increase" value="+" onclick="increaseBtnOnclick()"/>
关于javascript - HTML 表单加号按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9721061/