我是新手,剛開始學習javascript。我有兩個幾乎相同的腳本。這第一個工作正常,但我想知道爲什麼腳本在替換「document.getElementById(」counter「).value」var name「getValue」後停止工作。兩者都包含相同的代碼,對吧?通過var名稱替換代碼後腳本停止工作
Counter: <input type="text" id="counter" value="0">
<button onclick="myFunction()">Increase</button>
1.
<script>
function myFunction() {
var getValue = document.getElementById("counter").value;
++document.getElementById("counter").value;
}
</script>
2.
<script>
function myFunction() {
var getValue = document.getElementById("counter").value;
++getValue;
}
</script>
的getValue是局部的功能 – Satya