嘗試做一個測驗頁面,我需要在文字區域中寫入最少字元數後顯示「提交」按鈕。這是我嘗試過但無法使其發揮作用的方法。
<textarea name="tweet" id="textbox" rows="13" cols="70" placeholder="" maxlength="250"></textarea><br> <span id="char_count">0/250</span> <script> let textArea = document.getElementById("textbox"); let characterCounter = document.getElementById("char_count"); const minNumOfChars = 0; const maxNumOfChars = 250; var text = document.getElementById("buton"); const countCharacters = () => { let numOfEnteredChars = textArea.value.length; let counter = minNumOfChars + numOfEnteredChars; characterCounter.textContent = counter + "/250"; }; textArea.addEventListener("input", countCharacters); if (counter > 100 ) { text.style.display = "block"; } else { } </script> <br><br><br> <div> <button class="NextStep" id="buton" style="display:none" onclick="NextStep()">Finalizare Curs</button> </div> <script> function NextStep() { location.href =("Cursuri.html") } </script>
您的程式碼具有工作所需的所有必要部分,但您已經像畢卡索的畫作一樣重新建構了它!在正確的位置進行一些剪切-複製-貼上,就可以了!