简体   繁体   English

我试图用输入增加和减少数字来制作一个简单有趣的系统,但它不起作用

[英]I tried to make a simple fun system with increasing and decreasing numbers with input, but it doesnt work

I tried the script and its working well for the first 2 functions, but then when I added the third one, the entire page just doesn't work.我尝试了该脚本,它在前 2 个函数中运行良好,但是当我添加第三个函数时,整个页面都不起作用。 Can I know why and how to fix?我可以知道为什么以及如何解决吗?

I am a beginner Javascripter and I still need practices so can you guys explain someway suitable for my level?我是初学者 Javascripter,我仍然需要练习,所以你们能解释一下适合我的水平吗?

 let a = 0, b = 1 function inc() { a += b document.getElementById("x").innerHTML = "x" + " " + "=" + " " + a; }; function dec() { a -= b document.getElementById("x").innerHTML = "x" + " " + "=" + " " + a; }; function input() { if (document.getElementById("input").innerHTML == null) { } else { b = Number(document.getElementById("input").innerHTML); }; };
 body { background-color: powderblue; }
 <h1>Online simple Javascript project!</h1> <p id="x">x = 0</p><!-- Result --> <p><br><br>Change the power here!</p><!-- // Description --> <input id="input"><button type="button" onclick="input()">Apply</button><!-- // Button that save your power --> <h2>Click the button to increase x</h2><!-- // Description --> <button type="button" onclick="inc()">Increase</button><!-- // Increase --> <h2>Click the button to decrease x</h2><!-- // Description --> <button type="button" onclick="dec()">Decrease</button><!-- // Decrease -->

Use value instead of innerHTML for input使用value代替innerHTML进行input

function input() {
  if (document.getElementById("input").value != null){
    b = Number(document.getElementById("input").value);
  };
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 增加或减少输入值 - increasing or decreasing the input value 我无法对数组中的数字进行排序(尝试了此处编写的所有内容,stil无法正常工作) - I can't sort numbers in an array (tried everything that was written here, stil doesnt work) PHP制作一个简单的计算器 - 代码不起作用 - PHP Make a simple calculator - Code doesnt work 高图增加/减少来自输入的数据 - Highcharts increasing/decreasing data from input 我试图制作一个代码,在从用户那里输入 2 个数字时,生成一个随机数 - I have tried to make a code that on getting input of 2 numbers from the user, generates a random number 我尝试将文本组件发送到屏幕末端,但是它不起作用 - I tried to send text component to end of screen but it doesnt work 我试图为学校开一张彩票,但是当我不得不画数字时,它不起作用(第59行) - Im trying to make a lottoticket for school, but when i have to draw the numbers it doesnt work(line 59) 简单的node.js修改,如何确定变量是增加还是减少? - Simple node.js modification, how to determine if a variable is increasing or decreasing? 为什么这个 html javascript 文件不起作用,我怎样才能让用户输入不是正数? - why this html javascript file doesnt work and how can i make user input to not be anything but positive number? 使用 Vue.js 将数组长度增加和减少到输入范围值 - Increasing & decreasing an array length to a input range value with Vue.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM