表单/表格

Bootstrap4动态模态窗口jQuery插件

也想出现在这里?联系我们
创客主机


这是一款Bootstrap4动态模态窗口jquery插件。通过该jquery插件,可以动态生成bootstrap4的模态窗口,可以实现简单的弹出框,对话框,以及复杂结构的模态窗口。

使用方法

在页面中引入jquery.min.js、bootstrap-show-modal.js文件,以及bootstrap4相关文件。

  1. <link rel="stylesheet" href="css/bootstrap.min.css"/>
  2. <script  src="js/jquery.min.js"></script>        
  3. <script  src="js/bootstrap.bundle.min.js"></script>        
  4. <script  src="js/bootstrap-show-modal.js"></script>

实现弹出框

  1. $.showModal({title: "Hello World!", body: "A very simple modal dialog without buttons."})

实现对话框

  1. $.showAlert({title: "Hi", body: "Please press ok, if you like or dislike cookies."})

实现确认框

  1. $.showConfirm({
  2.     title: "Please confirm", body: "Do you like cats?", textTrue: "Yes", textFalse: "No",
  3.     onSubmit: function (result) {
  4.         if (result) {
  5.             $.showAlert({title: "Result: " + result, body: "You like cats."})
  6.         } else {
  7.             $.showAlert({title: "Result: " + result, body: "You don't like cats."})
  8.         }
  9.     },
  10.     onDispose: function () {
  11.         console.log("The confirm dialog vanished")
  12.     }
  13. })

实现复杂的对话框

  1. $.showModal({
  2.     title: 'Complex Form',
  3.     body:
  4.         '<form><div class="form-group row">' +
  5.         '<div class="col-3"><label for="text" class="col-form-label">Text</label></div>' +
  6.         '<div class="col-9"><input type="text" class="form-control" id="text"/></div>' +
  7.         '</div>' +
  8.         '<div class="form-group row">' +
  9.         '<div class="col-3"><label for="select" class="col-form-label">Select</label></div>' +
  10.         '<div class="col-9"><select id="select" class="form-control">' +
  11.         '<option value=""></option>' +
  12.         '<option value="red">red</option><option value="green">green</option><option value="blue">blue</option>' +
  13.         '</select></div>' +
  14.         '</div>' +
  15.         '<div class="form-group row">' +
  16.         '<div class="col-3"><label for="textarea" class="col-form-label">Textarea</label></div>' +
  17.         '<div class="col-9"><textarea id="textarea" rows="5" class="form-control"></textarea></div>' +
  18.         '</div></form>',
  19.     footer: '<button type="button" class="btn btn-link" data-dismiss="modal">Cancel</button><button type="submit" class="btn btn-primary">Send</button>',
  20.     onCreate: function (modal) {
  21.         // create event handler for form submit and handle values
  22.         $(modal.element).on("click", "button[type='submit']", function (event) {
  23.             event.preventDefault()
  24.             var $form = $(modal.element).find("form")
  25.             $.showAlert({
  26.                 title: "Result",
  27.                 body:
  28.                     "<b>text:</b> " + $form.find("#text").val() + "<br/>" +
  29.                     "<b>select:</b> " + $form.find("#select").val() + "<br/>" +
  30.                     "<b>textarea:</b> " + $form.find("#textarea").val()
  31.             })
  32.             modal.hide()
  33.         })
  34.     }
  35. })

Github网址:https://github.com/shaack/bootstrap-show-modal

(0)

本文由 创客云 作者:创客云 发表,转载请注明来源!

热评文章

发表评论

嘿,欢迎咨询!