我嘗試了該腳本,它在前 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 -->
uj5u.com熱心網友回復:
使用value而不是innerHTMLforinput
function input() {
if (document.getElementById("input").value != null){
b = Number(document.getElementById("input").value);
};
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/355549.html
標籤:javascript
