javascript - 如何使用 glitch.com 记录输入?
问题描述
我一直在使用 glitch.com 中的 HTML 代码,我想知道,我如何让某人输入输入并保存该输入,以便他或其他人可以看到它,有点像一条消息,并且即使我使用的是 HTML,有没有办法使用 JavaScript 的 console.log() 来记录它?
我尝试使用 JavaScript 创建变量并使用 console.log()。
JavaScript 代码:
console.log("logging function started");
let msg = prompt('Send message', "Enter text here");
alert(`${msg} has been sent!`);
console.log(msg + "has been sent!")
HTML 代码:
<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="/style.css">
<!-- import the webpage's javascript file -->
<script src="/script.js" defer></script>
</head>
<body>
<h1>input test</h1>
<form>
Student Name:<br> <input type="text" name="name">
<br>
Student Subject:<br> <input type="text" name="subject">
<br>
Rank:<br> <input type="text" name="rank">
</form>
<!-- include the Glitch button to show what the webpage is about and
to make it easier for folks to view source and remix -->
<div class="glitchButton" style="position:fixed;top:20px;right:20px;"></div>
<script src="https://button.glitch.me/button.js"></script>
</body>
</html>
注意:当我尝试创建变量并使用 console.log() 时,日志中没有显示任何内容。
解决方案
将您的<script>
标签移动到标签的底部<body>
。
另请参阅此答案:https ://stackoverflow.com/a/5329895/1651980
<!DOCTYPE html>
<html lang="en">
<head>
<title>test</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- import the webpage's stylesheet -->
<link rel="stylesheet" href="/style.css">
</head>
<body>
<h1>input test</h1>
<form>
Student Name:<br> <input type="text" name="name">
<br>
Student Subject:<br> <input type="text" name="subject">
<br>
Rank:<br> <input type="text" name="rank">
</form>
<!-- include the Glitch button to show what the webpage is about and
to make it easier for folks to view source and remix -->
<div class="glitchButton" style="position:fixed;top:20px;right:20px;"></div>
<script src="https://button.glitch.me/button.js"></script>
<!-- import the webpage's javascript file -->
<script src="/script.js" defer></script>
</body>
</html>
推荐阅读
- makefile - OpenWRT。Makefile 目标模式不包含“%”
- python - Ev3dev Python 更改 LineLeader Sensormode
- linux - 在 Google Cloud Shell 中自定义环境
- javascript - JavaScript html5 视频
- gradle - 如何从 Gradle 中的私有 Gitlab Maven 项目注册表存储库声明依赖项?
- java - 不使用 Docker 命令将文件从主机复制到 Docker 容器
- asp.net-mvc - ASP MVC - “个人帐户身份验证”项目数据库存储在哪里?
- webhooks - Zapier WebHook 从 CloudCMA 获取信息
- python - 如何根据两列在熊猫数据框中自定义排序?
- javascript - 如何在非单页面中的页面Vue之间共享数据