Home > Web Front-end > JS Tutorial > body text

Dailog_javascript techniques based on BootStarp

WBOY
Release: 2016-05-16 15:03:25
Original
1929 people have browsed it

Introduction to BootStrip

Bootstrap, from Twitter, is a very popular front-end framework.

Bootstrap is based on HTML, CSS, and JAVASCRIPT. It is simple and flexible, making web development faster. It was developed by Twitter designers Mark Otto and Jacob Thornton and is a CSS/HTML framework.

Bootstrap provides elegant HTML and CSS specifications, which are written in the dynamic CSS language Less. Bootstrap has been very popular since its launch and has been a popular open source project on GitHub, including NASA's MSNBC (Microsoft National Broadcasting Company) Breaking News. Some frameworks that are familiar to domestic mobile developers, such as the WeX5 front-end open source framework, are also based on the Bootstrap source code for performance optimization.

1.1. Help document keywords

boostrap modal box oaoDailog

1.2. Usage scenarios

When clicking a button on the web page, the user needs to be prompted for confirmation. The user can click the confirmation button to continue execution, or the user clicks the cancel button to cancel the execution operation;

When you click to view the web page and the displayed data needs to be displayed using a pop-up box, you can use oaoDailog

1.3. Schematic

Modal based on boostrap3.0, jquery1.9

1.4. Instructions for use

Why do you need oaoDailog?

a. Due to the modal provided by boostrap3.0, you must first define a modal div hidden code on the page, and the user writes the content that needs to be displayed into the div. If a page has multiple modal boxes, then It is necessary to write multiple hidden modal box div hidden codes, which is undoubtedly redundant.

b. Since the default modal does not have confirm and cancel buttons, of course we can write two buttons in the hidden div of the modal box, but we also need to write js to monitor the operations performed after the confirmation button is clicked, and at the same time The operation performed by the confirmation button is related to the data clicked by the user when it pops up. Bootstrap does not provide us with how to transfer the data.

c. oaoDailog 1.0.0 version mainly solves the problems of inconvenient use of bootstrap modal box and redundant code.

Rendering:

Get started

1. Introduce oaoDailog.js

Code:

<script type="text/javascript" src="${ctx}/static/jquery/jqueryApi/oaoDialog/oao.dialog.js" charset="UTF-8"></script>
Copy after login

2. Call the code to display the pop-up box

Code:

oao.dialog({
title:"删除提示框",
content:"请确认是否真的删除,删除后将无法恢复!",
ok:function(){
oao.dialog.close();
}
});
Copy after login

这就是一个基本也是使用最常见的确认弹出框的使用方法。

1.5. API

oao.dialog():这个方法是生成弹出框的方法,传入的参数是一个json对象,当然你也可以什么都不传,那样会弹出一个空白的弹出框,这是没有问题的。下面分别介绍每个参数的意思以及默认值。

属性名

属性类型

说明

默认值

title

String

弹出框标题

提示

content

String

弹出框的主要内容,可以是文本和html代码

okVal

String

确认按钮的自定义文字

确认

ok

Function/boolean

点击确认执行的方法

关闭功能

cancelVal

String

取消按钮的自定义文字

取消

cancal

Function/boolean

点击取消执行的方法

关闭功能

•oao.dialog.close():关闭模态框

1.6. 待支持的功能 1.目前弹出框的内容只支持文字和静态html,不支持url请求

2.目前最多只能显示两个按钮,不支持自定义按钮,后续支持

3.目前弹出框的位置和大小不支持自定义

4.目前的弹出框一次只能弹出一个,不支持弹出框中再弹出一个模态框(bootstrap modal底层不支持)

敬请期待,下个版本见。

/*!
* oaoDialog 1.0.0
* author:xufei
* Date: 2015-7-9 1:32
* http://www.oaoera.com
* Copyright &copy; 2014 www.oaoera.com Inc. All Rights Reserved. 沪ICP备13024515号-1 上海义信电子商务有限公司 
*
* This is licensed under the GNU LGPL, version 2.1 or later.
* For details, see: http://creativecommons.org/licenses/LGPL/2.1/
*/
//oao命名空间
oao = {};
oao.init = function(settings){
var defaultSettings ={
title : "提示",
content:"",
okVal:"确认",
cancalVal:"取消",
ok:function(){
$("#oaoModal").modal('hide');
},
cancel:function(){
$("#oaoModal").modal('hide');
},
close:false
}
oao.settings = $.extend({}, defaultSettings, settings || {});
return oao.settings;
}
oao.initContent = function(){
var modelHtml = 
"<div id=\"oaoModal\" class=\"modal fade delete_modal\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"true\" >"+
" <div class=\"modal-dialog\">"+
" <div class=\"modal-content\">"+
" <div class=\"modal-header\">"+
" <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\"><span aria-hidden=\"true\">×</span></button>"+
" <h4 class=\"modal-title\"></h4>"+
" </div>"+
" <div class=\"modal-body\" style=\"text-align:center;\">"+
" </div>"+
" <div class=\"modal-footer\">"+
" <button type=\"button\" class=\"btn btn-default modalCancel\"></button>"+
" <button type=\"button\" class=\"btn btn-primary modalOK\"></button>"+
" </div>"+
" </div>"+
" </div>"+
" </div>";
var $modelHtml = $(modelHtml);
$(".modalOK",$modelHtml).text(oao.settings.okVal);
$(".modalCancel",$modelHtml).text(oao.settings.cancalVal);
$(".modal-title",$modelHtml).text(oao.settings.title);
$(".modal-body",$modelHtml).html(oao.settings.content);
if(!oao.settings.ok){
$(".modalOK",$modelHtml).remove();
}
if(!oao.settings.cancel){
$(".modalCancel",$modelHtml).remove();
}
$("body").append($modelHtml);
}
//弹出对话框的方法
oao.dialog = function(settings){
settings = oao.init(settings);
oao.initContent();
//关闭的时候调用方法
$('#oaoModal').on('hidden.bs.modal', function (e) {
if(oao.settings.close){
oao.settings.close();
}
$("#oaoModal").remove();
})
if(oao.settings.ok){
$("#oaoModal .modalOK").click(settings.ok);
}
if(oao.settings.cancel){
$("#oaoModal .modalCancel").click(settings.cancel);
}
$("#oaoModal").modal('show')
.css({
"margin-top": function () {
return ($(this).height() / 2-200);
}
});;
}
//关闭对话框的方法
oao.dialog.close = function(){
$("#oaoModal").modal('hide');
}
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!