Bootstrap 彈出輸入框
阿新 • • 發佈:2019-01-01
效果
原理
- 引入
Bootstrap
和jQuery
- 在
彈框
中加入輸入框,同時自動獲得焦點
- 在
點選確定
,獲取輸入框的值
,進行相應流程操作
程式碼
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">×</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>