[英]What is the equivalent of Python's input() in Javascript?
I have looked for this, but haven't found anything similar. 我已经找到了,但是没有找到任何类似的东西。 In Javascript, I want to know if there is a way to get user input, from say a text area, in the middle of a loop, such as with the input() function from python.
在Javascript中,我想知道是否有一种方法可以在循环中间从文本区域获取用户输入,例如使用python的input()函数。 Here is an example:
这是一个例子:
def thing():
color = input("Pick Red, Yellow or Blue")
finished = False
previous = []
while finished == False:
if previous == []:
guess = "red"
response = input("Is your color red?")
previous.append((guess, response))
elif len(previous) == 1:
response = input("is your color blue?")
if response == "yes":
finished = True
This example is not exactly what I am trying to do but basically, I want a way, for a user to be asked things, and for them to put an answer in a text area(HTML), and push a button, which continues a Javascript while loop with the newly received input, and formulates some other question, and so on, until some condition is reached to stop the loop. 这个例子并不是我要尝试的,但基本上,我想要一种方法,让用户被问到事情,然后让他们在文本区域(HTML)中输入答案,然后按一个按钮,然后继续Javascript while用新接收到的输入循环,并提出其他问题,依此类推,直到达到某种条件才能停止循环。
Is this possible? 这可能吗? Does something in JS mimic this?
JS中的某些内容可以模仿吗?
Good old readline();
好的旧
readline();
https://developer.mozilla.org/En/SpiderMonkey/Introduction_to_the_JavaScript_shell#readline() https://developer.mozilla.org/En/SpiderMonkey/Introduction_to_the_JavaScript_shell#readline()
If you want to get value from text area then use : 如果要从文本区域获取价值,请使用:
<script>
function myFunction() {
var x = document.getElementById("myTextarea").value;
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.