结合jQuery、Bootstrap设计前端页面的代码
时间: 2023-12-31 15:04:09 浏览: 78
好的,以下是一个简单的结合jQuery、Bootstrap设计前端页面的示例代码:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Bootstrap Example</title>
<!-- 引入Bootstrap样式文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.3.1/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Example</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-6">
<form>
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" placeholder="Enter username">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
<div class="col-md-6">
<h2>jQuery Example</h2>
<p>Click the button to add a new list item at the end of the list.</p>
<button id="addBtn" class="btn btn-primary">Add Item</button>
<ul id="list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</div>
</div>
</div>
<!-- 引入jQuery文件 -->
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<!-- 引入Bootstrap JavaScript文件 -->
<script src="https://cdn.bootcss.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script>
$(function () {
// 点击按钮添加列表项
$('#addBtn').click(function () {
$('#list').append('<li>New Item</li>');
});
});
</script>
</body>
</html>
```
这个示例代码包含了一个导航栏和一个表单,同时使用了Bootstrap的样式和组件。在页面底部引入了jQuery和Bootstrap的JavaScript文件,同时使用了jQuery来处理页面的交互和动态效果。在这个示例中,点击按钮可以添加一个新的列表项。
阅读全文