前段时间刚刚接触了bootstrap,发现实在是太方便了,不用再多想那烦人的移动端设计了,而且也节省了很多写CSS样式的时间.
话不多说,直接上代码:
<body style="background-color: #999;">
<div class="container" style="margin-top: 10px;padding:30px;background-color: #e8e8e8;border-radius: 10px">
<div class="text-center">
<img src="img/2.jpg" width="300px" height="300px">
<h3>涛涛后台管理</h3>
</div>
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="name" class="col-sm-4 control-label">账号:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="name" placeholder="请输入你的用户名哦">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-4 control-label">密码:</label>
<div class="col-sm-4">
<input type="password" class="form-control" id="password" placeholder="请输入你的密码啊">
</div>
</div>
</form>
<!--放在class="form-horizontal"的表单中会影响模态框的显示-->
<div class="form-group">
<div class="col-sm-offset-5 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox">请记住我
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-5 col-sm-10">
<button id="submit" class="btn btn-success">登录</button>
</div>
</div>
</div>
<footer class="navbar-fixed-bottom">
<p class="text-center">Copyright @ 2019.taotao All Rights Reserved </p>
</footer>
<!-- 模态框(Modal) -->
<div class="modal fade" id="error" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 id="error_title">登陆失败,请重试</h4>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"></script>
在判断用户名和密码的情况上,我没写太多,就写了为空的情况.其实还有账号密码的个数,区分大小写等等...
<script>
$("#submit").click(function () {
var name = $("#name").val();
if(!name){
$("#error_title").text("账号不能为空!");
$("#error").modal("show");
setTimeout(function () {
$("#error").modal("hide");
},1200);
return false;
// 不在往下执行
}
var password = $("#password").val();
if(!password){
$("#error_title").text("密码不能为空!");
$("#error").modal("show");
setTimeout(function () {
$("#error").modal("hide");
},1200);
return false;
// 不在往下执行
}
});
</script>