繁体   English   中英

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

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

我尝试了该脚本,它在前 2 个函数中运行良好,但是当我添加第三个函数时,整个页面都不起作用。 我可以知道为什么以及如何解决吗?

我是初学者 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 -->

使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM