使用bootstrap 弹出效果演示

前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编辑功能,一般常见的主要有两种处理方式:行内编辑和弹出框编辑。在增加用户体验方面,弹出框和提示框起着重要的作用,如果你的系统有一个友好的弹出提示框,自然能给用户很好的页面体验。前面几章介绍了bootstrap的几个常用组件,这章来看看bootstrap里面弹出框和提示框的处理。总的来说,弹出提示主要分为三种:弹出框、确定取消提示框、信息提示框。本篇就结合这三种类型分别来介绍下它们的使用。

一、Bootstrap弹出框
使用过JQuery UI应该知道,它里面有一个dialog的弹出框组件,功能也很丰富。与jQuery UI的dialog类似,Bootstrap里面也内置了弹出框组件。打开bootstrap 文档可以看到它的dialog是直接嵌入到bootstrap.js和bootstrap.css里面的,也就是说,只要我们引入了bootstrap的文件,就可以直接使用它的dialog组件,是不是很方便。本篇我们就结合新增编辑的功能来介绍下bootstrap dialog的使用。废话不多说,直接看来它如何使用吧。

1、cshtml界面代码

<div class="modal fade" id="myModal" 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">
 
     <div class="form-group">
      <label for="txt_departmentname">部门名称</label>
      <input type="text" name="txt_departmentname" class="form-control" id="txt_departmentname" placeholder="部门名称">
     </div>
     <div class="form-group">
      <label for="txt_parentdepartment">上级部门</label>
      <input type="text" name="txt_parentdepartment" class="form-control" id="txt_parentdepartment" placeholder="上级部门">
     </div>
     <div class="form-group">
      <label for="txt_departmentlevel">部门级别</label>
      <input type="text" name="txt_departmentlevel" class="form-control" id="txt_departmentlevel" placeholder="部门级别">
     </div>
     <div class="form-group">
      <label for="txt_statu">描述</label>
      <input type="text" name="txt_statu" class="form-control" id="txt_statu" placeholder="状态">
     </div>
    </div>
    <div class="modal-footer">
     <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span>关闭</button>
     <button type="button" id="btn_submit" class="btn btn-primary" data-dismiss="modal"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存</button>
    </div>
   </div>
  </div>
 </div>

  最外面的div定义了dialog的隐藏。我们重点来看看第二层的div

<div class="modal-dialog" role="document">

  这个div定义了dialog,对应的class有三种尺寸的弹出框,如下:

<div class="modal-dialog" role="document">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-dialog modal-full" role="document">

  第一种表示默认类型的弹出框;第二种表示增大的弹出框;第三种表示满屏的弹出框。role="document"表示弹出框的对象的当前的document。

2、js里面将dialog show出来。
默认情况下,我们的弹出框是隐藏的,只有在用户点击某个操作的时候才会show出来。来看看js里面是如何处理的吧:

//注册新增按钮的事件
 $("#btn_add").click(function () {
  $("#myModalLabel").text("新增");
  $('#myModal').modal();
 });

  对,你没有看错,只需要这一句就能show出这个dialog.

$('#myModal').modal();

  摘抄网上文章地址:http://www.jb51.net/article/76013.htm

原文地址:https://www.cnblogs.com/searchbaidu/p/6051407.html