6.9.6 静态控件

6.9.6 静态控件

在某些情况下,需要在原本应该出现输入框的地方使用一段文本内容代替,此时可使用Bootstrap 的静态控件静态控件一般就是一个<p>元素,且需要为该元素指定.form-control-static样式

程序示例

例如如下页面示范了静态控件的用法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> 静态控件 </title>
<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../bootstrap/css/bootstrap-theme.min.css">
</head>

<body>
<div class="container">
<form action="http://www.fkit.org">
<!-- .form-group样式的元素作为容器 -->
<div class="form-group">
<label for="name">用户名</label>
<!-- 静态控件 -->
<p class="form-control-static">小王</p>
</div>
<div class="form-group">
<label for="passwd">密码</label>
<input type="password" class="form-control" id="passwd" placeholder="密码">
</div>
</form>
</div>
<script type="text/javascript" src="../jquery-3.1.1.js"></script>
<script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>
</body>

</html>

在水平表单中同样可通过.form-control-static样式来设置静态控件。

程序示例

例如如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> 静态控件 </title>
<link rel="stylesheet" href="../bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../bootstrap/css/bootstrap-theme.min.css">
</head>

<body>
<div class="container">
<!-- 水平表单 -->
<form action="http://www.fkit.org" class="form-horizontal">
<!-- .form-group样式表现出.row行为 -->
<div class="form-group">
<label for="name" class="col-sm-3 control-label">用户名</label>
<div class="col-sm-9">
<!-- 静态控件 -->
<p class="form-control-static">fkjava.org</p>
</div>
</div>
<div class="form-group">
<label for="passwd" class="col-sm-3 control-label">密码</label>
<div class="col-sm-9">
<input type="password" class="form-control" id="passwd" readonly placeholder="密码">
</div>
</div>
</form>
</div>
<script type="text/javascript" src="../jquery-3.1.1.js"></script>
<script type="text/javascript" src="../bootstrap/js/bootstrap.min.js"></script>
</body>

</html>