我想在我的浏览器中创建一个终端,但我不知道如何制作终端,以便如果我键入一个“命令”,它会响应“终端”中的一些东西。这里是我的代码:假终端浏览器 - 如何使它响应
<body>
<div id="screen">$><input></input></div>
<script>
$("#screen input").focus();
$("#screen input").on('keydown', function(event) {
if(event.which === 13) {// Enter key pressed
var $this = $(this),
val = $this.val();
$this.focus().val('');
if(val === "hello world") {
//respond with something in the terminal here
}
}
});
</script>
</body>
所以我只是想,当我做了命令的“Hello World”它这样应对的终端。
你擦除值以同样的方式...'$ this.val( '您好。');'。 – Santi
我希望它不在输入中,因此它不能被编辑@Santi – Gavwin
Scott在回复时发布了一个很好的解决方案,请查看他的答案。 – Santi