如何使用“提示”?和“警报” webstorm中的javascript命令? [英] How does one use "prompt" and "alert" javascript commands in webstorm?
问题描述
当我尝试使用提示或提醒来获取webstorm中的用户输入时,我收到错误:
When i try to use prompt or alert to get user input in webstorm, I get an error:
answers[i] = prompt(allQuestions[i].question)
^
ReferenceError:未定义提示
ReferenceError: prompt is not defined
据我所知,提示和警报是javascript中的优良功能。可能是因为我在控制台中运行代码?如果是这样,我如何将变量设置为用户输入的字符串(即提示功能)?如果没有,出现了什么问题以及如何修复它?
As far as I know, prompt and alert are fine functions in javascript. Could it be because I am running the code in the console? If so, how do I set variables to user inputted strings (i.e. prompt function)? If not, what's going wrong and how do I fix it?
推荐答案
通过在控制台中运行代码,是指你运行它与Node.js?但是'prompt'(以及'alert'等)不能在Node.js执行的服务器端脚本中使用。您只能通过客户端javascript提示用户,即通过呈现的HTML中的标记在浏览器中运行,而不是在服务器上运行的Javascript API引擎。
By running code in console, do you mean that you run it with Node.js? But 'prompt' (as well as 'alert', etc.) can't be used in server-side scripts executed by Node.js. You can only prompt the user with client-side javascript, i.e. running in the browser via a tag in the rendered HTML, not the Javascript API engine running on the server.
这篇关于如何使用“提示”?和“警报” webstorm中的javascript命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!