Bootstrap 弹出输入框

效果

这里写图片描述

原理

  • 引入 BootstrapjQuery
  • 弹框 中加入输入框,同时 自动获得焦点
  • 点击确定 ,获取 输入框的值 ,进行相应流程操作

代码

js

        // 修改弹出框的title, 显示弹框
        function ShowCreateModal(title){
            $("#createFileTitle").text(title);
            $('#createFileMModal').modal('show');
        }
        // 关闭弹框, 获取输入值,然后执行逻辑
        $("#createFileSureBut").click(function (){
            $("#createFileMModal").modal("hide");
            var inputFileName = $("#fileName").val();
            console.log("input file name : " + inputFileName);
        });

html

<div class="modal fade" id="createFileMModal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="createFileTitle">创建文件</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="fileName" class="col-form-label">文件名</label>
            <input type="text" autofocus class="form-control" id="fileName">
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary" id="createFileSureBut">确定</button>
      </div>
    </div>
  </div>
</div>
  • 6
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
Bootstrap提供了一个弹出(modal)组件,可以用于展示表单。以下是一个简单的例子: ```html <!-- Button to trigger modal --> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal"> Launch demo modal </button> <!-- Modal --> <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">Modal title</h4> </div> <div class="modal-body"> <form> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Email"> </div> <div class="form-group"> <label for="exampleInputPassword1">Password</label> <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> <div class="checkbox"> <label> <input type="checkbox"> Check me out </label> </div> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div> ``` 在这个例子中,我们使用了一个按钮来触发弹出。这个按钮使用了Bootstrap中的`data-toggle`和`data-target`属性来告诉浏览器要弹出哪个弹出。在弹出的HTML代码中,我们定义了一个表单,包含了一些输入框和复选。最后,我们还定义了一个保存按钮和一个关闭按钮,用于关闭弹出

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值