如何从Chrome的Javascript控制台获取输入? [英] How to get input from Chrome's Javascript console?
问题描述
有没有办法以编程方式从Google Chrome的JavaScript控制台获取输入,类似于
Is there a way to programmatically get input from the Javascript Console of Google Chrome, similar to readline()
in Firefox?
推荐答案
在Firefox中使用in-javascript> 这是一种接受输入的间接方法: This is an indirect method of taking inputs: 在JavaScript中声明一个函数: Declare a function in JavaScript: 由于Chrome的控制台基本上提供了与网页内容(如JavaScript变量,函数等)通讯的方法,因此将函数声明为可接收命令是一个选项。 As Chrome's console basically provides methods for communicating with the page's contents, like JavaScript variables, functions, etc., so declaring a function as a receivable command can be an option. 在控制台中,要提供输入,用户应输入: In the console, for providing input, the user shall type: 另一种解决方法是: Another workaround is: So the user can (more conveniently) type: 这篇关于如何从Chrome的Javascript控制台获取输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! readline
function your_command_here() {
//code
}
your_command_here()
your_command_here()
声明一个函数:
Declare a function:function command(var cmnd) {
switch(cmnd) {
case "command1":
//code
break;
}
}
$ b < br>
命令(user's command here)
command("user's command here")