无法在引导程序中使用jQuery html()

时间:2019-08-04 15:41:02

标签: bootstrap-4

无法在引导程序中使用html()jQuery函数

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
  <script>
        $(document).ready(function(){
          $("button").click(function(){
                        $('#alert').html('Wrong login. Please try again !');
          });
        });

  </script>
</head>
<body>

<div class="container">
  <h2>Vertical (basic) form</h2>
  <div class="text-danger" id="alert"></div>
  <form method="POST">
    <div class="form-group">
      <label for="email">Email:</label>
      <input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
    </div>
    <div class="form-group">
      <label for="pwd">Password:</label>
      <input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pwd">
    </div>
    <div class="checkbox">
      <label><input type="checkbox" name="remember"> Remember me</label>
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>
</div>

</body>
</html>

要在用户提交按钮后插入文本错误,但不起作用。看起来引导程序会在用户执行操作后覆盖文本。感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

如果按钮类型为Submit,将提交表单,因此您将看不到click功能的效果。将按钮的type =“ submit”更改为type =“ button”应该可以让您看到想要的内容。