春江暮客

ChatGPT自动生成网页

技术

这次使用爆火的chatgpt生成计算文字个数的网页。 问他用html,css,js生成计算文字个数的网页: write full code to count the number of words in a txt area, with html,css and javascript 回答如下:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Word Counter</title>
    <style>
      textarea {
        width: 100%;
        height: 200px;
        margin-bottom: 10px;
      }
      #count {
        font-size: 1.2em;
        color: #333;
        margin-bottom: 10px;
      }
    </style>
  </head>
  <body>
    <h1>Word Counter</h1>
    <textarea id="input" placeholder="Type your text here"></textarea>
    <div id="count"></div>
    <script>
      const input = document.getElementById("input");
      const count = document.getElementById("count");
      
      function updateCount() {
        const text = input.value.trim();
        const words = text.split(/\s+/);
        count.textContent = `Word count: ${words.length}`;
      }
      
      input.addEventListener("input", updateCount);
    </script>
  </body>
</html>

英文计算单词是没问题的,中文就不太行了。

Related