【发布时间】:2022-01-26 12:26:10
【问题描述】:
我用 html 为“终端”编写了一个脚本。
<html>
<head>
<title>Nonscript</title>
<div id="htmlterminal">
<center>
<pre>
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|H|T|M|L| |T|E|R|M|I|N|A|L| |M|A|D|E| |B|Y| |M|A|X|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
</pre>
</center>
</div>
<style>
#htmlterminal {
background: red;
background: -webkit-linear-gradient(left, orange, yellow, green, cyan, blue, violet);
background: -o-linear-gradient(right, orange, yellow, green, cyan, blue, violet);
background: -moz-linear-gradient(right, orange, yellow, green, cyan, blue, violet);
background: linear-gradient(to right, orange, yellow, green, cyan, blue, violet);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-size: 3vw;
}
#htmlterminal
</style>
</head>
<body style="background-color:Black;">
<p id="welcome" , style="color:white">Hello welcome to the HTML Terminal, for a list of commands type "help".</p>
<center>
<form class="pure-form">
<input id="command_prompt" type="text" placeholder="Enter command" />
<button type="submit">Run<i class="fa fa-chevron-circle-right"></i></button>
</form>
</center>
<p id="return" , style="color:white"></p>
<script>
var commandPrompt = document.getElementById('command_prompt');
document.querySelector('form.pure-form').addEventListener('submit', function(e) {
e.preventDefault();
document.getElementById("return").innerHTML = "Executing: " + commandPrompt.value;
});
</script>
</body>
</html>
我尝试使用if 来检查输入,但它似乎工作正常,这是我的代码:
if commandPrompt.value = "help" {
document.getElementById("return").innerHTML = "Some more commands come here"
}
else{
return null
}
我浏览了网页,但仍然没有找到任何东西,我可以寻求帮助吗?,
谢谢,布利泽尔
【问题讨论】:
-
head部分中有 HTML 标记...它们必须在正文中! -
使用您的浏览器开发工具检查工具来查看报告的任何 JS 错误。对于 if 语句,使用 == 或 === 而不是一个 =。
-
谢谢@AHaworth 但还是不行。
标签: javascript html css terminal