線上預覽 下載
這是一款Bootstrap4動態模態視窗jquery外掛。透過該jquery外掛,可以動態生成bootstrap4的模態視窗,可以實現簡單的彈出框,對話方塊,以及複雜結構的模態視窗。
使用方法
在頁面中引入jquery.min.js、bootstrap-show-modal.js檔案,以及bootstrap4相關檔案。
< link rel = "stylesheet" href = "css/bootstrap.min.css" /> < script src = "js/jquery.min.js" ></ script > < script src = "js/bootstrap.bundle.min.js" ></ script > < script src = "js/bootstrap-show-modal.js" ></ script > |
實現彈出框
$.showModal({title: "Hello World!" , body: "A very simple modal dialog without buttons." }) |
實現對話方塊
$.showAlert({title: "Hi" , body: "Please press ok, if you like or dislike cookies." }) |
實現確認框
$.showConfirm({ title: "Please confirm" , body: "Do you like cats?" , textTrue: "Yes" , textFalse: "No" , onSubmit: function (result) { if (result) { $.showAlert({title: "Result: " + result, body: "You like cats." }) } else { $.showAlert({title: "Result: " + result, body: "You don't like cats." }) } }, onDispose: function () { console.log( "The confirm dialog vanished" ) } }) |
實現複雜的對話方塊
$.showModal({ title: 'Complex Form' , body: '<form><div class="form-group row">' + '<div class="col-3"><label for="text" class="col-form-label">Text</label></div>' + '<div class="col-9"><input type="text" class="form-control" id="text"/></div>' + '</div>' + '<div class="form-group row">' + '<div class="col-3"><label for="select" class="col-form-label">Select</label></div>' + '<div class="col-9"><select id="select" class="form-control">' + '<option value=""></option>' + '<option value="red">red</option><option value="green">green</option><option value="blue">blue</option>' + '</select></div>' + '</div>' + '<div class="form-group row">' + '<div class="col-3"><label for="textarea" class="col-form-label">Textarea</label></div>' + '<div class="col-9"><textarea id="textarea" rows="5" class="form-control"></textarea></div>' + '</div></form>' , footer: '<button type="button" class="btn btn-link" data-dismiss="modal">Cancel</button><button type="submit" class="btn btn-primary">Send</button>' , onCreate: function (modal) { // create event handler for form submit and handle values $(modal.element).on( "click" , "button[type='submit']" , function (event) { event.preventDefault() var $form = $(modal.element).find( "form" ) $.showAlert({ title: "Result" , body: "<b>text:</b> " + $form.find( "#text" ).val() + "<br/>" + "<b>select:</b> " + $form.find( "#select" ).val() + "<br/>" + "<b>textarea:</b> " + $form.find( "#textarea" ).val() }) modal.hide() }) } }) |