如何将文本框值处理为 JavaScript 中的变量

How to Process textbox value to variable in JavaScript

我希望能够在文本框中输入内容,然后得到一个 alert 说明我输入的内容。简单吧?我尝试使用 getElementbyId 并制作了一些变量来适应这个,但结果它给出了未定义的。 这是代码:

    <input type="submit" name="button" style="position: absolute; top: 283.5px; left: 45%; width: 142px; height: 40px; background-color:lime; border-color:forestgreen; font-weight:700; font-family:'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif" value="CLICK ME"/>
    <div style="position: absolute; top: 283.5px; left: 23%; width: 142px; height: 40px; background-color:lime; border-color:forestgreen;">
        <input type="text" name="linksubmit" id="linksubmit" style="position: absolute; top: 10px; width:138px" />
    </div>
    <script>
        var linksubmit = document.getElementById("linksubmit").value 
        function Button() {
            alert(linksubmit)
        }
    </script>

如果你们中的任何人有正当理由说明这无法正常工作,我们将不胜感激。

该值仅在您的函数被调用之前被捕获一次。你需要更多类似的东西:

        var linksubmit = document.getElementById("linksubmit"); 
        function Button() {
            // Get the value each time the button is pressed, instead of reporting
            // an old, stale value (probably empty string/null/undefined.)
            alert(linksubmit.value);
        }

const theThing = document.getElementById('testerooni');
showMe = () => { alert(theThing.value) };
<input id="testerooni" type="text">
<button onclick="showMe()">SHOW ME</button>