为什么在 HTML 终端模拟器中创建颜色命令会创建(大部分)白色屏幕?
我正在制作一个 HTML 终端,并且已经完成了大部分样式设计。不过,我正在尝试添加一个命令,这会改变颜色。您可以运行这些代码片段,看看我为什么要问这个问题,但是当您输入颜色然后输入颜色时,它不会执行我想要执行的操作,它只会给您一个(大部分)白色屏幕。
$('body').terminal({
iam: function(name) {
this.echo('Hello, ' + name +
'. Welcome to Coding Class!');
},
echo: function(what) {
this.echo(what)
},
link: function(link) {
window.location.replace("http://www." + link);
},
color: function(color) {
var body = document.querySelector("body");
body.className = "test";
var temp = document.querySelectorAll(".test");
for (var i = 0; i < temp.length; i++) {
temp[i].style.color = color;
temp[i].style.fontSize = "40px";
}
}
}, {
greetings: 'Hi!',
prompt: 'root> '
})
<head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js">
</script>
<script src="https://unpkg.com/jquery.terminal/js/jquery.terminal.min.js">
</script>
<link rel="stylesheet" href="https://unpkg.com/jquery.terminal/css/jquery.terminal.min.css" />
</head>
<body>
</body>
I am making an HTML terminal, and have done most of the styling. I am trying to add one command, though, which will change the color. You can run these code snippets, and see why I'm asking this, but when you type in color and then a color, instead of doing what I'm trying to make it do, it just gives you a (mostly) white screen.
$('body').terminal({
iam: function(name) {
this.echo('Hello, ' + name +
'. Welcome to Coding Class!');
},
echo: function(what) {
this.echo(what)
},
link: function(link) {
window.location.replace("http://www." + link);
},
color: function(color) {
var body = document.querySelector("body");
body.className = "test";
var temp = document.querySelectorAll(".test");
for (var i = 0; i < temp.length; i++) {
temp[i].style.color = color;
temp[i].style.fontSize = "40px";
}
}
}, {
greetings: 'Hi!',
prompt: 'root> '
})
<head>
<script src="https://code.jquery.com/jquery-3.3.1.min.js">
</script>
<script src="https://unpkg.com/jquery.terminal/js/jquery.terminal.min.js">
</script>
<link rel="stylesheet" href="https://unpkg.com/jquery.terminal/css/jquery.terminal.min.css" />
</head>
<body>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要以更简单的方式更改终端的颜色,您还可以执行以下操作:
To change the terminal's color in a more simple way you could also do:
我将向您展示如何在
body
中使用add()
CSS 类名。为了在命令
color
上更改背景颜色,我将代码更改为使用setProperty()
来设置 CSS 变量,因为 CSS 文件本身已经在使用该变量(在 < code>.terminal 类),这样更容易。I'm showing you how to use
add()
CSS class name tobody
.To make background color change on command
color
, I change the code to usesetProperty()
to set CSS variable instead because the CSS file itself is already use that variable (in.terminal
class) and it is easier this way.