整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

表格数据通过点击传数据给Bootstrap模态窗口

表格数据通过点击传数据给Bootstrap模态窗口
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link href="css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/font-awesome.min.css" />
		<style>
			li {
				list-style: none;
			}
			.modal-li li {
				height: 45px;
				line-height: 45px;
			}
			.text-input {
				display: inline-block;
				width: 80%;
				margin-left: 10px;
			}
		</style>
	</head>
	<body>
		<!--主页面数据 start-->
		<div style="margin:50px;">
			<table class="table table-bordered">
			 <thead>
			 <tr>
			 <th>姓名</th>
			 <th>编号</th>
			 <th>性别</th>
			 <th>修改</th>
			 </tr>
			 </thead>
			 <tbody>
			 <tr>
			 <td>龙彻</td>
			 <td>20160621</td>
			 <td>男</td>
			 <td style="color:#f00;cursor:pointer;" onclick="editInfo(this)">修改</td>
			 </tr>
			 <tr>
			 <td>Sachin</td>
			 <td>20160621111</td>
			 <td>女</td>
			 <td style="color:#f00;cursor:pointer;" onclick="editInfo(this)">修改</td>
			 </tr>
			 <tr>
			 <td>Uma</td>
			 <td>23341</td>
			 <td>男</td>
			 <td style="color:#f00;cursor:pointer;" onclick="editInfo(this)">修改</td>
			 </tr>
			 </tbody>
			</table>
		</div>
		<!--主页面数据 start-->
		
		<!--模态窗口 -->
		<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		 	<div class="modal-dialog" role="document">
			 <div class="modal-content">
			 	<div class="modal-header">
				 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
				 	<span aria-hidden="true">×</span>
				 </button>
				 <h4 class="modal-title" id="myModalLabel">模态窗口</h4>
			 	</div>
				 <div class="modal-body modal-li">
				 	<form>
				 	 	<ul>
				 	 		<li>
				 	 			<label for="name">姓名</label>
	 							<input type="text" class="form-control text-input" id="name" placeholder="请输入姓名">
				 	 		</li>
				 	 		<li>
				 	 			<label for="name">编号</label>
	 							<input type="text" class="form-control text-input" id="number" placeholder="请输入编号">
				 	 		</li>
				 	 		<li>
				 	 			<label for="name">性别</label>
	 							<input type="radio" name="sex" id="man" value="男" style="margin-left:10px;"/>男 
 					<input type="radio" name="sex" id="women" value="女" style="margin-left:10px;"/>女 
				 	 		</li>
				 	 	</ul>
				 	</form>
				 </div>
				 <div class="modal-footer">
				 <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				 <button type="button" class="btn btn-primary" onclick="update()">保存</button>
				 </div>
			 </div>
		 	</div>
		</div>
		<!--end-模态窗口 -->
		<script src='js/jquery-1.10.2.min.js'></script>
		<script src="js/bootstrap.min.js"></script>
	</body>
</html>			

s:

bootstrap框架中,使用模态框(modal)的弹窗组件需要三层 div 容器元素,分别为:

1. 外层:modal(模态声明层)。

2. 中间层:dialog(窗口声明层)。

3. 内层:content(内容层)。在内容层里面,还包含三层,分别为 header(头部)、body(主体)、footer(注脚)。

案例效果如下:

说明:案例中设置按钮的数据切换方式(data-toggle)是modal,数据目标(data-target)指向模态框的id(mod1)。

网页文件modal.html的代码如下:

<!doctype html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">

<title>模态框插件</title>

<link rel="stylesheet" href="css/bootstrap.css">

<style type="text/css">

*{

margin:0px;

padding:0px;

}

body{

font-size:14px;

}

</style>

</head>

<body>

<!--tabindex="-1"表示关闭焦点,使得按esc键也可以关闭打开的对话框 -->

<div class="modal fade" id="mod1" tabindex="-1">

<div class="modal-dialog modal-sm">

<div class="modal-content">

<div class="modal-header">

<button class="close" data-dismiss="modal"><span>&times;</span></button>

<h4 class="modal-title">用户登陆</h4>

</div>

<div class="modal-body">

<div class="input-group">

<span class="input-group-addon">用户名:</span>

<input type="text" class="form-control" placeholder="请输入用户名">

</div>

<p></p>

<div class="input-group">

<span class="input-group-addon">密&nbsp;&nbsp;&nbsp;&nbsp;码:</span>

<input type="password" class="form-control" placeholder="请输入密码">

</div>

</div>

<div class="modal-footer">

<button class="btn btn-default">注册</button>

<button class="btn btn-primary">登陆</button>

</div>

</div>

</div>

</div>

<hr>

<button class="btn btn-primary" data-toggle="modal" data-target="#mod1">用户登陆</button>

<script src="js/jquery-3.1.1.min.js"></script>

<script src="js/bootstrap.js"></script>

</body>

</html>

至此,案例制作完成。

为美工详情页增加模态框效果,可以采用以下步骤和技巧:

  1. 决定模态框的触发方式:首先,确定何时触发模态框的出现。常见的触发方式包括点击按钮、链接或图片,或者通过特定的交互行为,如鼠标悬停或滚动。
  2. 设计模态框的外观:根据页面的整体风格和需求,设计模态框的外观。考虑选择合适的颜色、字体、背景和边框样式,以与页面保持一致并提升视觉吸引力。
  3. 创建模态框的内容:确定模态框中要展示的内容,可以是文本、图片、视频、表单等。根据需求设计和布局模态框的内容,确保信息的清晰度和易读性。
  4. 编写模态框的交互行为:使用HTML、CSS和JavaScript编写模态框的交互行为。设置合适的事件处理程序,以实现模态框的打开、关闭和交互效果。
  5. 添加动画和过渡效果:为模态框添加动画和过渡效果,以增加页面的动态感和流畅性。可以使用CSS过渡和动画属性,如opacity、transform和transition,来实现平滑的过渡和动画效果。
  6. 响应式设计考虑:确保模态框在不同屏幕尺寸和设备上的适应性。使用响应式设计技术,如媒体查询和弹性布局,使模态框能够自动调整大小和布局,以适应不同的屏幕。
  7. 测试和优化:在完成模态框设计后,进行充分的测试,并根据用户反馈和体验进行优化。确保模态框在不同浏览器和设备上的兼容性,并检查其与页面其他元素的交互和一致性。

通过以上步骤和技巧,你可以成功为美工详情页设计增加模态框效果。模态框可以提供一种交互式和聚焦式的用户体验,增加页面的互动性和吸引力。