点击事件上的简单 JavaScript 不起作用

问题描述 投票:0回答:1

有一个 CSS 文件和 js 文件是为自定义粒子引擎背景复制的。如果这个文件不是问题,我可以发布它们,但它们非常复杂。还有另一个 CSS 文件来设置下面 html 代码的样式

代码如下。

function handleClick() {
  alert("Button clicked!");
}
<!-- File-->
<!DOCTYPE html>
<html lang="en-US">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>homePage</title>

  <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">


  <script src="../static/background.js" defer></script>
  <script src="https://code.createjs.com/1.0.0/easeljs.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/gsap.min.js"></script>

  <link rel="stylesheet" href="../static/background1.css">
  <link rel="stylesheet" href="../static/signInPage.css">
</head>

<body>

  <!-- Heading's Color ans size -->
  <h1>

    <span class="welcome">Hello &amp; Welcome To:</span>
    <span class="redRat"> THE RED RAT'S ACRCHIVES </span>

  </h1>


  <!-- Paragraph text -->
  <p class="welcomeMessage"> This is a collection containing the most popular browser games from all over the internet with games that are old and new. <br> I hope you will enjoy and share with your friends.<br> </p>
  <br>
  <p class="createAccountMessage"> Please sign in or create an account to access the website</p>

  <!-- Log In Buttons-->
  <div class="createAccountButton">
    <button onclick="handleClick()" id="createAccount" type="button" class="btn btn-outline-light">Create Account</button>
  </div>

  <div class="signInButton">
    <button type="button" class="btn btn-outline-light">Sign In</button>
  </div>

  <!-- Paragraph text -->
  <p class="contactInfo"> email me at [email protected] with any feedback, recommendations, or errors you encounter </p>

  <canvas id="projector" width="800" height="600"></canvas>


</body>

</html>

我尝试过使用事件监听器并将js代码放在其他文件中。我尝试了调试和检查错误以及其他基本的 js 功能。我不知道。当单击 createAccount 按钮时,我期待一个基本的 js 警报。创建警报功能是为了确保 Js 代码在我的程序中正常运行。

javascript button onclick event-listener
1个回答
0
投票

它对我有用,我将其转储到 html 文件中,并且创建帐户事件侦听器正在触发。 enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.