在控制台中使用JavaScript接受用户输入 [英] Take user input with JavaScript in the console

查看:5050
本文介绍了在控制台中使用JavaScript接受用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在具有spidermonkey的控制台中运行 .js 时获取用户输入,如下所示:



$ js myprogram.js



Ruby的 $ c>?

解决方案

据我所知,有一个readline()函数,但它是一个特定的函数



1)readline-test.js:

  print(键入一些文本,然后按< ENTER>:\t ; 
var userInput = readline();
print(User input:+ userInput);

2)js readline-test.js



有关详情,请参见 https://developer.mozilla.org/en-US / docs / SpiderMonkey / Introduction_to_the_JavaScript_shell


I need to get user input when running a .js in a console with spidermonkey like this:

$ js myprogram.js

What's the JavaScript equivalent of Ruby's gets?

解决方案

As far as i know, there is a readline() function, but it is a specific function for spidermonkey, it isn't a part of javascript.

Example:

1)readline-test.js:

print("Type some text and press <ENTER>:\t");
var userInput = readline();
print("User input: " + userInput);

2)js readline-test.js

For more information see https://developer.mozilla.org/en-US/docs/SpiderMonkey/Introduction_to_the_JavaScript_shell.

这篇关于在控制台中使用JavaScript接受用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆