我想在我的瀏覽器中創建一個終端,但我不知道如何製作終端,以便如果我鍵入一個「命令」,它會響應「終端」中的一些東西。這裏是我的代碼:假終端瀏覽器 - 如何使它響應
<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