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>

猜你喜欢

转载自blog.csdn.net/ai_shuyingzhixia/article/details/81255095
今日推荐