1

我目前的项目

我正在尝试使用 jQuery 终端制作一个终端样式的网页。

我的问题

我不知道如何向终端添加多个命令。

这是我的代码:

$('body').terminal({
      hello: function(name) {
          this.echo('Hello, ' + name +
                    '. Welcome to the Rapocrythia command line.');
      }
  }, {
      greetings: 'Rapocrythia Command Line[Version 0.0.1]\n(c) Copyright Rapocrythia Systems, Inc. All Rights Reserved.'
  }
);
4

1 回答 1

0

只需向第一个参数添加更多属性。

$('body').terminal({
  hello: function(name) {
    this.echo('Hello, ' + name +
      '. Welcome to the Rapocrythia command line.');
  },
  add: function(num1, num2) {
    this.echo(parseInt(num1) + parseInt(num2));
  },
  bye: function() {
    this.echo('So long');
  }
}, {
  greetings: 'Rapocrythia Command Line[Version 0.0.1]\n(c) Copyright Rapocrythia Systems, Inc. All Rights Reserved.'
});
<link href="https://unpkg.com/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/jquery.terminal/js/jquery.terminal.min.js"></script>

如果您键入add 10 15它将打印25.

于 2020-07-22T19:45:44.093 回答