js-jquery-SweetAlert2【三】INPUT TYPES
1、text
swal({
title: 'Input something',
input: 'text',
showCancelButton: true,
inputValidator: function (value) {
return new Promise(function (resolve, reject) {
if (value) {
resolve()
} else {
reject('You need to write something!')
}
})
}
}).then(function (result) {
swal({
type: 'success',
html: 'You entered: ' + result
})
})
2、email
swal({
title: 'Input email address',
input: 'email'
}).then(function (email) {
swal({
type: 'success',
html: 'Entered email: ' + email
})
})
3、password
swal({
title: 'Enter your password',
input: 'password',
inputAttributes: {
'maxlength': 10,
'autocapitalize': 'off',
'autocorrect': 'off'
}
}).then(function (password) {
if (password) {
swal({
type: 'success',
html: 'Entered password: ' + password
})
}
})
4、textarea
swal({
input: 'textarea',
showCancelButton: true
}).then(function (text) {
if (text) {
swal(text)
}
})
5、select
swal({
title: 'Select Ukraine',
input: 'select',
inputOptions: {
'SRB': 'Serbia',
'UKR': 'Ukraine',
'HRV': 'Croatia'
},
inputPlaceholder: 'Select country',
showCancelButton: true,
inputValidator: function (value) {
return new Promise(function (resolve, reject) {
if (value === 'UKR') {
resolve()
} else {
reject('You need to select Ukraine :)')
}
})
}
}).then(function (result) {
swal({
type: 'success',
html: 'You selected: ' + result
})
})
6、radio
// inputOptions can be an object or Promise
var inputOptions = new Promise(function (resolve) {
setTimeout(function () {
resolve({
'#ff0000': 'Red',
'#00ff00': 'Green',
'#0000ff': 'Blue'
})
}, 2000)
}) swal({
title: 'Select color',
input: 'radio',
inputOptions: inputOptions,
inputValidator: function (result) {
return new Promise(function (resolve, reject) {
if (result) {
resolve()
} else {
reject('You need to select something!')
}
})
}
}).then(function (result) {
swal({
type: 'success',
html: 'You selected: ' + result
})
})
7、checkbox
swal({
title: 'Terms and conditions',
input: 'checkbox',
inputValue: 1,
inputPlaceholder:
'I agree with the terms and conditions',
confirmButtonText:
'Continue <i class="fa fa-arrow-right></i>',
inputValidator: function (result) {
return new Promise(function (resolve, reject) {
if (result) {
resolve()
} else {
reject('You need to agree with T&C')
}
})
}
}).then(function (result) {
swal({
type: 'success',
text: 'You agreed with T&C :)'
})
})
8、file
swal({
title: 'Select image',
input: 'file',
inputAttributes: {
accept: 'image/*'
}
}).then(function (file) {
var reader = new FileReader
reader.onload = function (e) {
swal({
imageUrl: e.target.result
})
}
reader.readAsDataURL(file)
})
9、range
swal({
title: 'How old are you?',
type: 'question',
input: 'range',
inputAttributes: {
min: 8,
max: 120,
step: 1
},
inputValue: 25
})
10、多输入框
不支持多输入框,但是可以使用html and preConfirm自己来实现
swal({
title: 'Multiple inputs',
html:
'<input id="swal-input1" class="swal2-input">' +
'<input id="swal-input2" class="swal2-input">',
preConfirm: function () {
return new Promise(function (resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val()
])
})
},
onOpen: function () {
$('#swal-input1').focus()
}
}).then(function (result) {
swal(JSON.stringify(result))
}).catch(swal.noop)


js-jquery-SweetAlert2【三】INPUT TYPES的更多相关文章
- (三)在js(jquery)中获得文本框焦点和失去焦点的方法
在js(jquery)中获得文本框焦点和失去焦点的方法 文章介绍两个方法和种是利用javascript onFocus onBlur来判断焦点和失去焦点,加一种是利用jquery $(" ...
- js+jquery+html实现在三种不通的情况下,点击图片放大的效果
js+jquery+html实现在三种不通的情况下,点击图片放大的效果. 三种情况分别是:图片的父元素宽高固定; 图片的宽高固定; 图片的父元素宽固定,高度不固定 第一种情况:图片的父元素宽高固定 ...
- js/jquery 获取本地文件的文件路劲 获取input框中type=‘file’ 中的文件路径(转载)
原文:http://blog.csdn.net/niyingxunzong/article/details/16989947 js/jquery 获取本地文件的文件路劲 获取input框中type= ...
- js/jquery/html前端开发常用到代码片段
1.IE条件注释 条件注释简介 IE中的条件注释(Conditional comments)对IE的版本和IE非IE有优秀的区分能力,是WEB设计中常用的hack方法.条件注释只能用于IE5以上,IE ...
- js/jQuery实现类似百度搜索功能
一.页面代码:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...
- jquery.form.js+jquery.validation.js实现表单校验和提交
一.jquery引用 主要用到3个js: jquery.js jquery.form.js jquery.validation.js 另外,为了校验结果提示本地化,还需要引入jquery.vali ...
- JQuery(三)-- AJAX的深入理解以及JQuery的使用
HTTP HTTP http: 超文本传输协议.特点: 简单.快速.灵活.无状态.无连接 URL: 统一资源定位符. 组成:协议名://主机IP:端口号/项目资源地址?传递参数的键值对#锚点 ①ip ...
- js jquery css 选择器总结
js jquery css 选择器总结 一.原始JS(Document 对象)选择器. id选择器:document.getElementById("test"); name选择器 ...
- JS/Jquery版本的俄罗斯方块(附源码分析)
转载于http://blog.csdn.net/unionline/article/details/63250597 且后续更新于此 1.前言 写这个jQuery版本的小游戏的缘由在于我想通过从零到有 ...
- js&jquery获取指定table指定行里面的内容
js&jquery获取指定table指定行里面的内容 CreateTime--2018年5月18日11:46:04 Author:Marydon 1.展示 代码展示 <table s ...
随机推荐
- 学习 TList 类的实现[5]
先来实现 TMyList.SetCapacity. 马上会想到下面代码: procedure TMyList.SetCapacity(const Value: Integer); begin if ...
- Ubuntu下 Oracle sqldeveloper中文目录、文件,select查询结果中:中文乱码
是由于JDK所致.下面是网上的解决方案 解决案例1: .0_24/jre/lib/fonts.进入到fonts目录,新建文件夹 fallback cd /usr/java/jdk1..0_24/jre ...
- 各大门户网站全局CSS样式定义
1.网易 body { text-align: center; font-family:"宋体", arial;margin:0; padding:0; background: # ...
- ModelState.AddModelError使用
后台: ModelState.AddModelError("userPwd", "请输入密码!"); ModelState是一个字典类型,这句话的作用是向Mod ...
- NHibernate之映射文件配置说
1. hibernate-mapping 这个元素包括以下可选的属性.schema属性,指明了这个映射所引用的表所在的schema名称.假若指定了这个属性, 表名会加上所指定的schema的名字扩展为 ...
- swift--添加新手引导页
swift和oc逻辑上都是一样的,只是写法不一样,可以使用一个view,也可以使用一个viewController,两种都可以的,使用view注意初始化的时候给他一个frame,vc的话,直接在本控制 ...
- /var/log/cron
/var/log/cron 用来记录任务计划的运行日志,如下,分别表示: 任务运行的日期与时间 .在哪台主机上运行 .运行任务的程序[进程号] .任务运行的具体信息 [root@localhost ~ ...
- js如何判断不同的操作系统
<html> <head> <title>判断操作系统</title> <script type="text/javascript&qu ...
- java基础---->Java中图片的缩放
缩略图代表网页上或计算机中图片经压缩方式处理后的小图 ,其中通常会包含指向完整大小的图片的超链接.缩略图用于在 Web 浏览器中更加迅速地装入图形或图片较多的网页.今天,我们就开始java中图像的缩略 ...
- 在腾讯云服务器上体验Docker
版权声明:本文由姚俊刚原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/85 来源:腾云阁 https://www.qclou ...