使用jquery封装一个可以复用的提示框
首先在html中
<div class="backcap">
<div class="diolag">
<div class="diolag-div">
<img class="diolag-icon" src="{{ basePath }}/img/solution/app/close.png">
<div class="img">
<img />
</div>
<h3 class="diolag-title"></h3>
<p class="diolag-content"></p>
<button type="button" class="diolag-close">确定</button>
</div>
</div>
</div>
在script标签中
$(".backcap").hide()
//弹框时,每次整个页面变暗一点
//设置.backcap类名的元素显示,css样式见下文
var changeBack = function (){
$(".backcap").show()
}
//设置.backcap类名的元素不显示,css样式见下文
var changeCome = function (){
$(".backcap").hide()
}
//设置.diolag 我弹出框消失
$(".diolag").hide()
//设置.diolag 中的右侧X点击后,弹出框消失
$(".diolag .diolag-icon").click(function () {
$(".diolag").hide()
changeCome()
})
//设置.diolag 中的下面的按钮点击后,弹出框消失
$(".diolag .diolag-close").click(function () {
$(".diolag").hide()
changeCome()
})
//当我点击.submit的时候,先验证正则
$(".submit").click(function (){
// 获取正则手机号的数据
let contentData = $("#content").val()
let mobileData = $("#mobile").val()
let patt1=new RegExp("^1\\d{10}$")
//获取页面高度的方法
var getHeight = function (){
let _width = document.documentElement.clientWidth; //屏幕宽
let _height = document.documentElement.clientHeight; //屏幕高
let boxWidth = 580;//正常不应该写死的,由于需要我这里写死了
let boxHeight = 330;//正常不应该写死的,由于需要我这里写死了
// console.log(boxWidth,_width,_height)
$(".diolag").show();
$(".diolag .diolag-div").css({
"left": (_width - boxWidth) / 2 + `px`,
"top": (_height - boxHeight) / 2 + `px`
})
}
//信息有误的时候
var getFail = function (){
changeBack()
console.log('tel is wrong')
//这是电话有误
$('.diolag .diolag-title').text("提交失败!").css({"font-size": "18px", "color": "#3b426b","font-weight":"400"})
$('.diolag .img img').attr("src", "{{ basePath }}/img/solution/app/fail.png");
$('.diolag .diolag-content').text("老板, 您的手机号码填写有误,请确认填写正确后再提交一次吧!").css({
"font-size": "14px",
"color": "#7d88a2",
"line-height": "28px",
"margin-top": "160px"
})
}
// 提交成功时
var getSucess = function (){
changeBack()
console.log('success')
$('.diolag .diolag-title').text("提交成功!").css({"font-size": "18px", "color": "#3b426b","font-weight":"400"})
$('.diolag .img img').attr("src", "{{ basePath }}/img/solution/app/success.png");
$('.diolag .diolag-content').text("老板, 您的信息已提交成功, 保持预留手机的通畅, 我们将尽快与您取得联系哦!").css({
"font-size": "14px",
"color": "#7d88a2",
"line-height": "28px",
"margin-top": "160px"
})
}
// 重复提交时
var getAgain = function (){
changeBack()
console.log('getagain')
$('.diolag .diolag-title').text("重复提交!").css({"font-size": "18px", "color": "#3b426b","font-weight":"400"})
$('.diolag .img img').attr("src", "{{ basePath }}/img/solution/app/fail.png");
$('.diolag .diolag-content').text("老板, 您的信息已提交过啦, 请勿重复提交哦!").css({
"font-size": "14px",
"color": "#7d88a2",
"line-height": "28px",
"margin-top": "160px"
})
}
// 没有填写内容
var getNocont = function (){
changeBack()
console.log('getNocont')
$('.diolag .diolag-title').text("提交失败!").css({"font-size": "18px", "color": "#3b426b","font-weight":"400"})
$('.diolag .img img').attr("src", "{{ basePath }}/img/solution/app/fail.png");
$('.diolag .diolag-content').text("老板,您的需求信息还没有填写,请填写完整再提交哦!").css({
"font-size": "14px",
"color": "#7d88a2",
"line-height": "28px",
"margin-top": "160px"
})
}
let lock = true
getHeight()
if(!patt1.test(mobileData)){
//执行电话有误的事件
getFail()
}else {
let subData = {
content: contentData,
mobile: mobileData,
type: 100
}
//这是成功的
if(lock){
lock = false
//发送请求
$.ajax({
type:"POST",
url:"请求地址",
data:subData,
success:function(msg){
if(msg.error == "0"){
getSucess()
}else if(msg.error=="-1"){
getNocont()
}
}
})
}
}
})
css样式
.solution-app .backcap{
background: rgba(0,0,0,0.5);
position:fixed;
width:100%;
height:1200px;
z-index:160;
top:0px;
}
.solution-app .diolag{
height:330px;
position: relative;
text-align: center;
float:left;
}
.solution-app .diolag-div{
position: fixed;
z-index:200;
width:580px;
height:330px;
padding:16px 134px;
box-sizing: border-box;
border-radius: 10px;
background: white;
}
.solution-app .img {
position: absolute;
text-align: center;
margin:18px auto;
margin-bottom: 16px;
left:245px;
}
.solution-app .diolag .diolag-icon{
position:absolute;
right:18px;
width:30px;
height:30px;
top:18px;
color:#d0d0d0;
}
.solution-app .diolag .diolag-close{
height:40px;
width:100px;
color:#fff;
font-size:14px;
margin-top: 24px;
background: #599bff;
border-radius: 4px;
cursor: pointer;
}
.solution-app .diolag-title{
position: absolute;
margin:0 auto;
left:250px;
top:140px;
}
使用jquery封装一个可以复用的提示框的更多相关文章
- jquery 实现一个简单的成功提示框,失败提示框
主要的jquery代码:var TS={ successAlert:function(str){ //调用成功的方法 var html='<div class="alert alert ...
- JS~Boxy和JS模版实现一个标准的消息提示框
面向对象的封装 面向对象一个入最重要的特性就是“封装”,将一些没有必要公开的方法和属性以特定的方式进行组装,使它对外只公开一个接口,外界在调用它时,不需要关注它实现的细节,而只要关注它的方法签名即可, ...
- 基于Jquery 简单实用的弹出提示框
基于Jquery 简单实用的弹出提示框 引言: 原生的 alert 样子看起来很粗暴,网上也有一大堆相关的插件,但是基本上都是大而全,仅仅几句话可以实现的东西,可能要引入好几十k的文件,所以话了点时间 ...
- 基于jQuery封装一个瀑布流插件
/*封装一个瀑布流插件*/ (function($){ $.fn.WaterFall = function(){ /*这是你初始化 调用这个方法的时候的 那个jquery选着到的dom对象 this* ...
- 一个vue的全局提示框组件
<template> <!-- 全局提示框 --> <div v-show="visible" class="dialog-tips dia ...
- 【JS学习笔记】第一个JS效果——鼠标提示框
分析效果实现原理--鼠标提示框 样式:div的display 事件:onmouseover,onmouseout 编写JS的流程 布局:HTML+CSS 属性:确定需要修改哪些属性 事件:确定用户做哪 ...
- 仿照jquery封装一个自己的js库(一)
所谓造轮子的好处就是复习知识点,加深对原版jquery的理解. 本文系笔者学习jquery的笔记,记述一个名为"dQuery"的初级版和缩水版jquery库的实现.主要涉及知识点包 ...
- 仿照jquery封装一个自己的js库
所谓造轮子的好处就是复习知识点,加深对原版jquery的理解.本文系笔者学习jquery的笔记,记述一个名为"dQuery"的初级版和缩水版jquery库的实现.主要涉及知识点包括 ...
- 仿照jquery封装一个自己的js库(二)
本篇为完结篇.主要讲述如何造出轮子的高级特性. 一. css方法的高级操作 先看本文第一部分所讲的dQuery css方法 //css方法 dQuery.prototype.css=function( ...
随机推荐
- 基于Swagger+SpringBoot快速构建javaweb项目
章节导航 SpringBoot&Swagger简介 数据模型和接口定义 项目框架生成 业务逻辑实现 项目源码地址 github项目路径:https://github.com/Vikezhu/s ...
- h5页面在不同ios设备上的问题总结
1.日期问题 对于yyyy-mm-dd hh:mm:ss 这种格式在ios系统不识别 时间格式化的时候,在浏览器端处理好好的,到了手机端,就变成NAN,或者null,这种情况,是ios系统不能转化这种 ...
- 动态设置背景图片,class,style
1.动态设置背景图片<div v-if='img ' :style="{background: 'url('+ img +')',backgroundSize:cover }" ...
- 深入浅出 Java Concurrency (24): 并发容器 part 9 双向队列集合 Deque[转]
有一段时间没有更新了.接着上节继续吧. Queue除了前面介绍的实现外,还有一种双向的Queue实现Deque.这种队列允许在队列头和尾部进行入队出队操作,因此在功能上比Queue显然要更复杂.下图描 ...
- SPSS科普 | 统计描述
SPSS科普 | 统计描述 统计描述的目的就是了解数据的基本特征和分布规律,为进一步合理地选择统计方法提供依据.常用的有Frequencies.Descriptives 和Explore过程. 一.F ...
- SpringBoot学习笔记(七):SpringBoot使用AOP统一处理请求日志、SpringBoot定时任务@Scheduled、SpringBoot异步调用Async、自定义参数
SpringBoot使用AOP统一处理请求日志 这里就提到了我们Spring当中的AOP,也就是面向切面编程,今天我们使用AOP去对我们的所有请求进行一个统一处理.首先在pom.xml中引入我们需要的 ...
- C++ 函数模板&类模板详解
在 C++ 中,模板分为函数模板和类模板两种.函数模板是用于生成函数的,类模板则是用于生成类的. 函数模板&模板函数 类模板&模板类 必须区分概念 函数模板是模板,模板函数时 ...
- WhaleCTF之web-本地登录
WhaleCTF之web-本地登录 前往题目 呵呵,基然对ip限制,没事,掏出burp抓包 改包 添加XFF头部 X-Forwarded-For: 127.0.0.1 发一下 不是admin,没有用户 ...
- sed应用 升级场景配置文件更新 指定行追加
function addLine() { confFile=configuration.xml isExist=`cat ${confFile} | grep "<listen_ena ...
- C开发系列-continue与break
break break使用场景 switch语句:退出整个switch语句 循环结构:退出整个循环语句 while循环 do while循环 for 循环 continue continue使用场景 ...