1. 程式人生 > >Bootstrap 彈出輸入框

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>