简体   繁体   English

Sublime Text 2 - 无法为 prompt() 创建一个弹出框

[英]Sublime Text 2 - Not able to create a pop up box for prompt()

I began using Sublime Text 2 for my Javascript coding and love it.我开始使用 Sublime Text 2 进行 Javascript 编码并喜欢它。 I'm creating a small project that requires input from the user.我正在创建一个需要用户输入的小项目。 Normally, or from previous practice, I was able to write:通常,或者从以前的实践中,我能够写:

var x = prompt("What city do you live in?") and have the string assigned to the var x var x = prompt("你住在哪个城市?") 并将字符串分配给 var x

But, when I run this line of code in ST2 I get:但是,当我在 ST2 中运行这行代码时,我得到:

Exception: ReferenceError: Can't find variable: prompt.异常:ReferenceError:找不到变量:提示。

I've installed Package Control but can't find a plug-in to address my need.I installed SublimeREPL and that didn't work for me.我已经安装了 Package Control,但找不到满足我需求的插件。我安装了 SublimeREPL,但它对我不起作用。

Thanks, this is my first question on Stack.谢谢,这是我关于 Stack 的第一个问题。 Any comments or assistance is welcomed.欢迎任何意见或帮助。

you cannot run javascript in sublime text, the language to write plugins in python ,你不能在 sublime text 中运行 javascript,在 python 中编写插件语言

the SublimeREPL require extra binary to be installed to run Javascript (probably node.js), SublimeREPL 需要安装额外的二进制文件来运行 Javascript(可能是 node.js),

and even then the window.prompt is a browser API, not a javascript function (by default you are running at the window level which provide the default method with the need to prefix by the object name)即便如此, window.prompt是一个浏览器 API,而不是一个 javascript 函数(默认情况下,您在window级别运行,它提供了需要以对象名称作为前缀的默认方法)

In conclusion your Javascript console REPL in most case does not have the prompt function/method/API available总之,在大多数情况下,您的 Javascript 控制台 REPL 没有可用的提示功能/方法/API

I've never used JS to create sublime plugin, but you could use the function window.show_input_panel .我从未使用 JS 来创建 sublime 插件,但您可以使用函数window.show_input_panel Have a look at the sublime text 2 API .看看sublime text 2 API

Matt马特

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM