Javascript - User input through HTML input tag to set a Javascript variable?

前端 未结 4 1008
不思量自难忘°
不思量自难忘° 2021-02-03 14:11

I want there to be a textbox on my screen(like the one i\'m typing in now) that you can type in then click a submit button and it sends whatever you typed in the box to javascri

4条回答
  •  独厮守ぢ
    2021-02-03 14:35

    When your script is running, it blocks the page from doing anything. You can work around this with one of two ways:

    • Use var foo = prompt("Give me input");, which will give you the string that the user enters into a popup box (or null if they cancel it)
    • Split your code into two function - run one function to set up the user interface, then provide the second function as a callback that gets run when the user clicks the button.

提交回复
热议问题