javascript怎样实现点击加一
时间:2022-02-11 17:26
方法:1、给按钮元素绑定click点击事件,并指定时间处理函数;2、在事件处理函数中,利用“++”递加运算符实现计算加一效果,语法为“指定元素对象.value++;”。 本教程操作环境:windows10系统、javascript1.8.5版、Dell G3电脑。 javascript怎样实现点击加一 想要利用JavaScript实现点击加一,可以利用“++”递加运算符。 示例如下: 输出结果: 相关推荐:javascript学习教程 以上就是javascript怎样实现点击加一的详细内容,更多请关注gxlsystem.com其它相关文章!<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="text" value="0"><br><br>
<input type="submit" value="加一">
<script type="text/javascript">
var text = document.getElementsByTagName('input')[0];
var add = document.getElementsByTagName('input')[1];
add.onclick = function numberadd(){
text.value++;
}
</script>
</body>
</html>