jquery - JQuery 不适用于引导程序
问题描述
我在带有 Bootstrap 的 html5 中有一个简单的表单,但是我的 JQuery 无法正常工作,我正在尝试使用没有响应的简单警报。
<!DOCTYPE html>
<html>
<head>
<title>Index Tecatche</title>
<meta charset="utf-8"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/index.js"></script>
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" id="txt_email" placeholder="Email">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" id="txt_pass" placeholder="Password">
</div>
<input type="button" id="btn_enter" class="btn btn-primary" value="Enter">
<input type="button" id="btn_register" class="btn btn-primary" value="Register">
</body>
</html>
JS:
$("#btn_enter").click(function() {
alert("hi");
});
解决方案
只需将您的脚本放在 body 标记之后,并尝试不将 index.js 包含在您的以下库中
试试这个
$(document).ready(function(){
$("#btn_enter").click(function() {
alert("hi");
});
});
<!DOCTYPE html>
<html>
<head>
<title>Index Tecatche</title>
<meta charset="utf-8"/>
<link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" id="txt_email" placeholder="Email">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" id="txt_pass" placeholder="Password">
</div>
<input type="button" id="btn_enter" class="btn btn-primary" value="Enter">
<input type="button" id="btn_register" class="btn btn-primary" value="Register">
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!--<script src="js/bootstrap.min.js"></script>-->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</html>
推荐阅读
- c# - System.InvalidOperationException:没有为实体类型“BoundingBox”找到合适的构造函数
- c# - 列出所有使用 Reactjs 的 Azure DevOps 项目
- c++ - 针对错误的 OpenMP 并行
- maven-3 - Maven如何在战争中排除jar文件但需要它来构建
- authentication - 403 拒绝通过正确登录/通过谷歌脚本访问网站
- excel - 带有标准的 DAX LASTDATE 公式
- python - 在python中使用opencv库对图像进行阈值处理,使用for循环具有不同的标志
- reactjs - useGetOne 响应不会重新呈现组件
- python - 为什么我的 python 程序总是告诉我我的答案不正确,即使答案是错误的?
- javascript - 为什么下拉选择选项在某些移动设备中不起作用