1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ランダムな文字列を発生させるサイトをつくる

Posted at

index.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ランダムな文字列発生させるサイト</title>
    <link
      rel="stylesheet"
      href="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css"
      integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I"
      crossorigin="anonymous"
    />

    <style>
      body {
        margin: 0;
        background: #f7f7f7;
      }
      #wrap {
        overflow: hidden;
      }
      main {
        max-width: 750px;
        margin: 0 auto;
      }
    </style>
  </head>
  <body>
    <div id="wrap">
      <br />
      <main>
        <div class="input-group">
          <input type="number" id="num" class="form-control" value="8" />
          <div class="input-group-append">
            <button id="sumbit" class="btn btn-primary" type="button">
              作成
            </button>
          </div>
        </div>

        <br />
        <div class="input-group">
          <input id="text" class="form-control" readonly="" />
          <div class="input-group-append">
            <button id="copy" class="btn btn-success" type="button">
              コピー
            </button>
          </div>
        </div>
      </main>
    </div>
    <script
      src="https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js"
      integrity="sha384-oesi62hOLfzrys4LxRF63OJCXdXDipiYWBnvTl9Y9/TRlw5xlKIEHpNyvvDShgf/"
      crossorigin="anonymous"
    ></script>

    <script>
      document.getElementById('sumbit').onclick = () => {
        const _s = 'abcdefghijklmnopqrstuvwxyz0123456789';
        const _ret = [...Array(Number(document.getElementById('num').value))]
          .map(() => _s[Math.floor(Math.random() * _s.length)])
          .join('');
        document.getElementById('text').value = _ret;
      };

      document.getElementById('copy').onclick = () => {
        document.getElementById('text').select();
        document.execCommand('copy');
      };
    </script>
  </body>
</html>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?