输入框
密码框
下拉列表【重新渲染】
是加入layui-form 引入form模块
lay-search="" 是否支持下拉输入过滤
单选框【重新渲染】
是加入layui-form 引入form模块
复选框【重新渲染】
是加入layui-form 引入form模块
lay-skin="primary" 使用原始的样式
开关【重新渲染】
是加入layui-form 引入form模块
使用checkbox实现
lay-skin="switch" 使用皮肤
文本域
富文本
//初始化表单
$("#btn2").click(function(){
form.val("dataFrm",{
username:'张大明',
pwd:'123456',
phone:'13311112222',
email:'[email protected]',
jiguan:'北京',
sex:'女',
//hobby:["写作","阅读","游戏"],
ishere:false
});
var hobby="写作,游戏";
var hobbys=hobby.split(",");
//得到hobbyElem
var hobbyElem=$("[name='hobby']");
$.each(hobbys,function(i,str){
alert(str);
$.each(hobbyElem,function(j,item){
var jdom=$(item);// 把dom--转jdom
if(jdom.val()==str){
//jdom.attr({"checked",true});
jdom.attr("checked","checked");
}
})
})
form.render();
});
使用方法
lay-verify="required|phone"
相关的值
required 非空验证
phone 手机号验证
number 数值验证
url 链接地址验证 http://www.baid.com
自定义验证
json要求
{
"title": "相册标题",
"id": 123,
"start": 0,
"data": [
{
"alt": "图片名1",
"pid": 5,
"src": "resources/images/img1.jpg",
"thumb": "resources/images/img1.jpg"
},
{
"alt": "图片名3",
"pid": 1,
"src": "resources/images/img3.jpg",
"thumb": "resources/images/img3.jpg"
},
{
"alt": "图片名4",
"pid": 2,
"src": "resources/images/img4.jpg",
"thumb": "resources/images/img4.jpg"
},
{
"alt": "图片名5",
"pid": 3,
"src": "resources/images/img5.jpg",
"thumb": "resources/images/img5.jpg"
},
{
"alt": "图片名6",
"pid": 4,
"src": "resources/images/img6.jpg",
"thumb": "resources/images/img6.jpg"
}
]
}
//alert
$("#btn1").click(function() {
var x=layer.open({
type:0, //设置类型 默认为0 1 页面层 2ifream层
title:"提示", //标题
content:'你好吗?',//内容 type=0为内容
skin :'layui-layer-molv',//皮肤
/* area: '500px' */
area:['500px','300px'],//宽高
offset: 'auto', //offset默认情况下不用设置。但如果你不想垂直水平居中
icon:1 //只对type=0的效
, btn: ['按钮一', '按钮二', '按钮三']
,yes: function(index, layero){
//按钮【按钮一】的回调
alert("按钮一");
layer.close(index);
}
,btn2: function(index, layero){
//按钮【按钮二】的回调
alert("按钮二")
//return false 开启该代码可禁止点击该按钮关闭
}
,btn3: function(index, layero){
//按钮【按钮三】的回调
alert("按钮三")
//return false 开启该代码可禁止点击该按钮关闭
}
,cancel: function(){
//右上角关闭回调
alert("cancel")
//return false 开启该代码可禁止点击该按钮关闭
}
,btnAlign :'c' //按钮的对齐方式
,closeBtn : 1 //设置关闭按钮的样式 1 默认
,shade: [0.8, '#FF0000']
,shadeClose:true //点击遮罩是否关闭弹层
,anim: 4 //设置动画
,maxmin :true //是否显示最大化和最小化的按钮 type=1 type=2有效
,success:function(layero, index){
alert(index+" "+x);
}
})
alert(x);
});
页面层 把页面上的某一段HTML代码放到弹出层里面
此时的content属性可以使用html代码
也可以使用页面元素的选择器
type=2时是一个ifream层
此时的content就是一个页面的url
准备json
{
"code": 0,
"msg": "",
"count": 101,
"data": [
{
"id": "10001",
"username": "杜甫",
"email": "[email protected]",
"sex": "男",
"city": "浙江杭州",
"sign": "点击此处,显示更多。当内容超出时,点击单元格会自动显示更多内容。",
"experience": "116",
"ip": "192.168.0.8",
"logins": "108",
"joinTime": "2016-10-14"
},
{
"id": "10002",
"username": "李白",
"email": "[email protected]",
"sex": "男",
"city": "浙江杭州",
"sign": "君不见,黄河之水天上来,奔流到海不复回。 君不见,高堂明镜悲白发,朝如青丝暮成雪。 人生得意须尽欢,莫使金樽空对月。 天生我材必有用,千金散尽还复来。 烹羊宰牛且为乐,会须一饮三百杯。 岑夫子,丹丘生,将进酒,杯莫停。 与君歌一曲,请君为我倾耳听。(倾耳听 一作:侧耳听) 钟鼓馔玉不足贵,但愿长醉不复醒。(不足贵 一作:何足贵;不复醒 一作:不愿醒/不用醒) 古来圣贤皆寂寞,惟有饮者留其名。(古来 一作:自古;惟 通:唯) 陈王昔时宴平乐,斗酒十千恣欢谑。 主人何为言少钱,径须沽取对君酌。 五花马,千金裘,呼儿将出换美酒,与尔同销万古愁。",
"experience": "12",
"ip": "192.168.0.8",
"logins": "106",
"joinTime": "2016-10-14",
"LAY_CHECKED": true
},
{
"id": "10003",
"username": "王勃",
"email": "[email protected]",
"sex": "男",
"city": "浙江杭州",
"sign": "人生恰似一场修行",
"experience": "65",
"ip": "192.168.0.8",
"logins": "106",
"joinTime": "2016-10-14"
},
{
"id": "10004",
"username": "李清照",
"email": "[email protected]",
"sex": "女",
"city": "浙江杭州",
"sign": "人生恰似一场修行",
"experience": "666",
"ip": "192.168.0.8",
"logins": "106",
"joinTime": "2016-10-14"
},
{
"id": "10005",
"username": "冰心",
"email": "[email protected]",
"sex": "女",
"city": "浙江杭州",
"sign": "人生恰似一场修行",
"experience": "86",
"ip": "192.168.0.8",
"logins": "106",
"joinTime": "2016-10-14"
},
{
"id": "10006",
"username": "贤心",
"email": "[email protected]",
"sex": "男",
"city": "浙江杭州",
"sign": "人生恰似一场修行",
"experience": "12",
"ip": "192.168.0.8",
"logins": "106",
"joinTime": "2016-10-14"
},
{
"id": "10007",
"username": "贤心",
"email": "[email protected]",
"sex": "男",
"city": "浙江杭州",
"sign": "人生恰似一场修行",
"experience": "16",
"ip": "192.168.0.8",
"logins": "106",
"joinTime": "2016-10-14"
},
{
"id": "10008",
"username": "贤心",
"email": "[email protected]",
"sex": "男",
"city": "浙江杭州",
"sign": "人生恰似一场修行",
"experience": "106",
"ip": "192.168.0.8",
"logins": "106",
"joinTime": "2016-10-14"
}
]
}
可以使用html实现[了解]
可以使用js 实现[掌握]
数组表格
field:和数据接口里面的data[{"id":1}]的key映射
title:表头的内容
width:宽度
hide:true 是否隐藏
sort:true 是否开启列排序
edit:true 是否支持编辑
align:'center' 内容对齐方式 left center right
templet:function(d){return d.sex=='男'?'汉子':'妹子';}}
totalRowText:"合计" 合计行的文本 前提是表格开启合并行
totalRow:true 是否合计前提是表格开启合并行
toolbar: '#userBar' 引入行的工具栏
前提单元必须可以编辑
{
"code": 0,
"msg": "",
"count": 101,
"data": [
{
"id": "10001",
"username": "杜甫",
"email": "[email protected]",
"sex": "1",
"city": "浙江杭州",
"LAY_CHECKED":true
},
{
"id": "10002",
"username": "李白",
"email": "[email protected]",
"sex": "1",
"city": "浙江杭州",
"LAY_CHECKED": true
},
{
"id": "10003",
"username": "王勃",
"email": "[email protected]",
"sex": "1",
"city": "浙江杭州"
},
{
"id": "10004",
"username": "李清照",
"email": "[email protected]",
"sex": "0",
"city": "浙江杭州"
},
{
"id": "10005",
"username": "冰心",
"email": "[email protected]",
"sex": "0",
"city": "浙江杭州"
},
{
"id": "10006",
"username": "贤心",
"email": "[email protected]",
"sex": "1",
"city": "浙江杭州"
},
{
"id": "10007",
"username": "贤心",
"email": "[email protected]",
"sex": "1",
"city": "浙江杭州"
},
{
"id": "10008",
"username": "贤心",
"email": "[email protected]",
"sex": "1",
"city": "浙江杭州"
}
]
}
数组表格
//普通图片上传
var uploadInst = upload.render({
elem: '#test1'
,url: 'file/upload.action'
,accept:'images'
,acceptMime:'image/*'
,auto:true//是否选择文件之后自动上传
,field:'mf' //表单的name值
,before: function(obj){
//预读本地文件示例,不支持ie8
obj.preview(function(index, file, result){
$('#demo1').attr('src', result); //图片链接(base64)
});
}
,done: function(res){
alert(res);
//如果上传失败
if(res.code > 0){
return layer.msg('上传失败');
}
//上传成功
layer.msg("上传成功");
}
,error: function(){
//演示失败状态,并实现重传
var demoText = $('#demoText');
demoText.html('上传失败 重试');
demoText.find('.demo-reload').on('click', function(){
uploadInst.upload();
});
}
});