HTML/CSS/Javascript 在线代码运行工具

在线代码运行工具

在线代码运行工具


工具代码

<html>
<head>
  <meta charset="utf-8">
  <title>在线代码运行工具</title>
  <style>
    #editor {
      width: 100%;
      height: 400px;
      border: 1px solid #ccc;
      padding: 10px;
      font-size: 16px;
    }
    button {
      padding: 10px 20px;
      font-size: 16px;
      background-color: #4CAF50;
      color: white;
      border: none;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <h1 style="text-align: center;">在线代码运行工具</h1>
  <textarea id="editor"></textarea>
  <br>
  <div style="text-align: center;">
    <button id="run-button">运行</button>
  </div>

  <script>
    const runButton = document.getElementById("run-button");
    const editor = document.getElementById("editor");

    runButton.addEventListener("click", function() {
      const newWindow = window.open();
      newWindow.document.write(editor.value);
    });
  </script>
</body>
</html>

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注