gpt4 book ai didi

javascript - 如何使用 glitch.com 记录输入?

转载 作者:行者123 更新时间:2023-12-02 22:50:03 25 4
gpt4 key购买 nike

我一直在 glitch.com 中摆弄 HTML 代码,我想知道如何让某人输入一个输入并保存该输入,以便他或其他人可以看到它,有点像消息,有没有办法使用 JavaScript 的 console.log() 记录它,即使我使用的是 HTML?

我尝试使用 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>

关于javascript - 如何使用 glitch.com 记录输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58220482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com