QGLDialog是轻攻略的一个免费开源弹窗插件,您可以自由使用而不用支付费用,可以商用不用担心版权问题。QGLDialog支持常见的对话框如:confirm、alert、prompt以及错误提示、处理提醒等。

QGLDialog是在jQuery下开发的,所以需要先安装jQuery。

最新版本

jquery-3.5.1 qgldialog-src-3.1 qgldialog-min-3.1

代码示例

请将要放入弹框的内容放在id="QGLBox"的容器中。也可自定义$(element).QGLDialog({'box':'#QGLBox'}); 其中的QGLBox换成自定义的ID即可,默认会自动寻找ID为QGLBox的容器。

常用参数说明
{
	title: '',                //弹框标题
	box: '#QGLBox',           //弹框默认选择器
	width: 300,               //弹框默认宽度
	height: 270,              //弹框默认高度
	positions: 'center',      //弹框位置(默认center:居中,top:顶部居中,left:顶部居左,bottom:底部居右)
	hideTime: 0,              //弹框定时关闭(默认0:不自动关闭,以毫秒为单位)
	modalHide: true,          //是否点击遮罩背景关闭弹框(默认true:关闭,false:不可关闭)
	isOverlay: true,          //是否显示遮罩背景(默认true:显示,false:不显示)
	escHide: true,            //是否支持ESC关闭弹框(默认true:关闭,false:不可关闭)
	closebtn : "",            //自定义的关闭按钮
	autoShow: false,          //是否页面加载完成后自动弹出(默认false点击弹出,true:自动弹出)
	iframeSrc: '',            //弹框类型为iframe时使用的 链接地址,有则为iframe
	iframeId: 'iframeQGLBox', //弹框类型为iframe时使用的 ID
	beforeShow: function(){}, //显示前的回调方法
	afterHide: function(){},  //隐藏后的回调方法
	buttons:{}
}
$(function(){
	$.QGLDialog({title:'页面加载完成后自动执行', height: 350});
});
默认打开
$(function(){
	$('.demo1').QGLDialog(); //绑定调用, class为demo1的点击执行
});
绑定调用
$(function(){
	$('.demo2').QGLDialog({title: '弹框标题'}); 
});
带标题
$(function(){
	$('.demo3').QGLDialog({width:600,height: 500});
});
改变宽和高
$(function(){
	$('.demo4').QGLDialog({beforeShow: function(){
		alert('显示前执行');
	}});
});
显示前回调
$(function(){
	$('.demo5').QGLDialog({positions: 'bottom'});
});
改变位置
$(function(){
	$('.demo6').QGLDialog({afterHide: function(){
		alert('隐藏后执行');
	}});
});
隐藏后回调
$(function(){
	$('.demo7').QGLDialog({modalHide: false});
});
遮罩不可点击关闭
$(function(){
	$('.demo8').QGLDialog({isOverlay: false});
});
不显示遮罩
$(function(){
	$('.demo9').QGLDialog({hideTime: 2000});
});
定时关闭
$(function(){
	$('.demo50').QGLDialog({iframeSrc:'about:blank',iframeId:'iframeQGLBox',width:960,height:600});
});
iframe框架
$('.demo11').click(function(){
	$.tipFalse('My God, 出错啦!!!');
});
错误提示
$('.demo12').click(function(){
	$.tipTrue('OK, 操作成功!');
});
正确提示
$('.demo13').click(function(){
	$.tipTrue('提示后回调',function(){
		alert('执行回调...');
	});
});
提示后回调
$('.demo14').click(function(){
	//自定义文字: $.showLoading('玩命加载中...');
	$.showLoading();
});
显示加载
$(function(){
	$('.demo15').QGLDialog({title: '测试弹框标题',height: 500, isOverlay: false,
	buttons: {
		"确定1": {
			id: "ok", action: function (obj) {
				alert($(obj).html());
			}
		}, "确定2": {
			id: "ok2", action: function (obj) {
				alert($(obj).html());
			}
		}, "确定3": {
			id: "ok3", action: function (obj) {
				alert($(obj).html());
			}
		}
	}});
});
添加按钮
$(function(){
	$('.demo16').confirm('提示','您确认要删除么?',function(){ 
		alert('等待回调执行');
	});
});
对话框
$(function(){
	$('.demo17').alert('提示','正在处理中...',function(){ alert('等待回调执行,'+$(this).html()); }); 
});
弹窗
$(function(){
	$('.demo18').click(function(){
		$.prompt('提示','请输入口令',function(v){ 
			alert('口令:'+v); 
		},"#ff0000");

	});
});
输入框
$(function(){
	$('.demo19').click(function(){
		//confirm、alert、prompt
		$.dialog('confirm','提示','您确认要删除么?',3000,function(){ 
			alert('等待回调执行自动隐藏'); 
		});

	});
});
对话框自动隐藏
$('.demo20').click(function(){
	$.tooltip('hello...',1000,true,function(){
		$.tooltip('执行回调...');
	});
	$.tip('hello...',true,function(){
		$.tooltip('执行回调...');
	});
});
提示自定义
$('.demo21').click(function(){
	$.content('提示',['姓名','密码'],function(v){ 
		alert('姓名:'+v[0]+' 密码:'+v[1]); 
	},"#ff0000");
});
自定义多值对话框
$('.demo22').click(function(){
	$.content('提示',"<b>内容</b>",function(v){ 
		alert("回调函数"); 
	},"#ff0000");
});
自定义Html对话框
$(function(){
	//链接数组可以生成菜单,也可以指定html或纯文本,true,表示跟随点击位置
	$('.demo23').tipShow( [
		["javascript:alert();", "Example 1"],
		["https://example.org", "Example 2"],
		["https://example.net", "Example 3"]
	],true);
});
迷你菜单
$(function(){
	//只显示标题和内容,无按钮,可在回调函数中关闭
	$('.demo24').on("click",function (){
		$.msg("发表","提交中...",function(){
			alert("自定回调函数");
			// $.closeDialog();
		});
	});
});
msg不关闭含遮罩层
  • 昵 称 *
  • 手 机 *
  • 邮 箱 *
  • 性 别  
  • 爱 好  

本插件基于hDialog二次开发,遵循《MIT License》
Copyright (c) 2016 He HaiBao
Copyright (c) 2024 轻攻略