【问题标题】:How to Create More Than One Command in a jQuery Terminal Environment如何在 jQuery 终端环境中创建多个命令
【发布时间】:2020-07-22 15:42:23
【问题描述】:

我目前的项目

我正在尝试使用 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.'
  }
);

【问题讨论】:

  • 有很多jquery终端插件,你有你正在使用的那个文档的链接吗?
  • 这是docs

标签: javascript jquery jquery-terminal


【解决方案1】:

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

$('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

【讨论】:

  • 你不需要在参数上使用 parseInt,jQuery Terminal 默认解析数字。
猜你喜欢
  • 2020-06-22
  • 2016-04-05
  • 2020-07-23
  • 2012-12-11
  • 1970-01-01
  • 1970-01-01
  • 2021-08-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多