Как мне регистрировать входы, используя glitch.com? - PullRequest
0 голосов
/ 03 октября 2019

Я возился с HTML-кодом на glitch.com, и мне интересно, как я могу заставить кого-то вводить данные и сохранять их, чтобы они были видны ему или другим людям, вроде каксообщение, и есть ли способ зарегистрировать его с помощью JavaScript console.log (), хотя я использую HTML?

Я пытался создать переменные и использовать console.log () с помощью JavaScript.

Код 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 (), в журналах ничего не отображалось.

1 Ответ

0 голосов
/ 03 октября 2019

Переместите тег <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>

...