jQuery-confrim模态框

jQuery-confrim基本简单实列

一。 需要引入的文件,下面需要引入的文件中是在模态框里需要使用到bootstrap中的类似于图标,布局。。。这些时才需要引入相关的文件,否则不需要引入相关的文件
<!--外部jQuery文件-->
		<script type="text/javascript" src="jquery-1.8.2.min.js" ></script>
		<!--demo文件中的-->
			<link rel="stylesheet" href="demo/libs/bundled.css" />
		<!--demo文件中的-->
		<!--dist文件夹中的-->
			<link rel="stylesheet" href="dist/jquery-confirm.min.css" />
			<script src="dist/jquery-confirm.min.js"></script>
		<!--dist文件夹中的-->
		<!--bootstrap文件引入 可选-->
		<link type="text/css" rel="stylesheet" href="bootstrap/css/bootstrap.css">
	    <script type="text/javascript" src="bootstrap/js/bootstrap.js"></script>
		<!--bootstrap文件引入-->
		<script>
二。警示框
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
		//这里由于要预先加载,所以要放在$(function()
		$(function(){
			//演示实列1 警示框
			$("#demo1").click(function(){
				$.alert({
				    title: '警示框', //这里是警示框标题
				    content: '简单实例!', //这里是内容
				    type: 'purple',//模态框头部的颜色
				});
			});
		})
		</script>
	</head>
	<body>
		<button id="demo1">演示实例1</button>
	</body>
</html>

三。确认框
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
		//这里由于要预先加载,所以要放在$(function()
		$(function(){
			//演示实例2 确认框
			$("#demo2").click(function(){
				$.confirm({
				    title: '确认框',//这里是警示框标题
				    content: '简单实例',//这里是内容
   				    type: 'green',//模态框头部的颜色
				    buttons: {
				        confirm: function () {
				            $.alert('确认!');
				        },
				        cancel: function () {
				            $.alert('取消');
				        },
				        somethingElse: {
				            text: '还有别的',
				            btnClass: 'btn-orange',
				            keys: ['a', 'b'],
				            action: function(){
				                $.alert('别的什么!');
				            }
				        }
				    }
			    });
			});
		})
		</script>
	</head>
	<body>
		<button id="demo2">演示实例2</button>
	</body>
</html>
三。对话框
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
		//这里由于要预先加载,所以要放在$(function()
		$(function(){
			//演示实列三,对话框
			$("#demo3").click(function(){
				$.confirm({
						icon: 'glyphicon glyphicon-heart',
					    title: '对话框',
					    content: '' +
					    '<form action="" class="formName">' +
					    '<div class="form-group">' +
					    '<label>标题</label>' +
					    '<input type="text" placeholder="请输入" class="name form-control" required />' +
					    '</div>' +
					    '</form>',
					    buttons: {
					        formSubmit: {
					            text: '提交',
					            btnClass: 'btn-green',//这里可以更改按钮的颜色
					            action: function () {
					                var name = this.$content.find('.name').val();
					                if(!name){
					                    $.alert('输入项不能为空');
					                    return false;
					                }
					                $.alert('你输入的是' + name);
					            }
					        },
					        cancel: function () {
					            //close
					        },
					    },
					    onContentReady: function () {
					        // bind to events
					        var jc = this;
					        this.$content.find('form').on('submit', function (e) {
					            // if the user submits the form by pressing enter in the field.
					            e.preventDefault();
					            jc.$$formSubmit.trigger('click'); // reference the button and click it
					        });
					    }
					});
			});
			
		})
		</script>
	</head>
	<body>
		<button id="demo3">演示实例3</button>
	</body>
</html>
四。文本框
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
		//这里由于要预先加载,所以要放在$(function()
		$(function(){
			//演示实列4文本框
			$("#demo4").click(function(){
				$.dialog({
				    title: '你好啊!',
				    content: '我是TWG!',
				    draggable:false, //限制模态框是否可以被移动,false不能移动,true可以移动
				    theme:'material',//改变模态框的主题样式可选的有'dark','light','material','bootstrap'
				});
			});
		})
		</script>
	</head>
	<body>
		<button id="demo4">演示实例4</button>
	</body>
</html>

注意:

1. 本实列中 . c o n f i r m ( ) .confirm(), .dialog()和$.alert()方法的别名jconfirm()。
所有这三种方法间接调用jconfirm基函数来改变提供的选项

五。相关参数以下分别代表 |名称| |默认值| |描述|
title:'Hello'
//默认值是Hello,对话框的标题。还接受一个返回字符串的函数。
type:'default'
//将default改变成其他的颜色就可以更换模态框头部的颜色可用选项包括:'蓝色,绿色,红色,橙色,紫色和深色'
draggable:false
//设定模态框是否可以移动,true是可以移动,fasle不可以移动
icon:''
//图标类前置在标题之前。例如:'fa fa-icon'也可以使用bootstrap中的图标
theme:'light'
//可以更改主题样式默认微light还可以选用'light', 'dark', 'material' 'bootstrap'
animation:'zoom'
//模态框弹出时的方向动画,还可以选用right,left,bottom,top,rotate,none,opacity,scale,zoom,scaleY,scaleX,rotateY,rotateYR(reverse),rotateX,rotateXR(reverse)v1.1.2 

以上文档参数只是部分,如果还需要用到更多或者想学习更多可以到相关的官方网站查看API文档网址,如果想学习更多可以参考我的 ==>下一篇文章

  1. API文档参考网址 http://craftpip.github.io/jquery-confirm/#api
  2. 下载jQuery-confrim地址 http://craftpip.github.io/jquery-confirm/
  3. 下载地址: https://pan.baidu.com/s/11M2l0_4LCYKK4t2KXwF8Fg 密码:n0yv

特别注意:

  1. 在引入文件时,需要将jQuery文件放在引入文件的最前面不然无法出现效果
  2. 需要使用bootstrap中的文件时需要在头部引入bootstrap相关文件
发布了19 篇原创文章 · 获赞 7 · 访问量 6635

猜你喜欢

转载自blog.csdn.net/William_TWG/article/details/84952924