2016-10-14 16:23:52 +08:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
2017-02-21 06:48:54 +08:00
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>表单模块 - layui</title>
|
|
|
|
<meta name="renderer" content="webkit">
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
|
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|
|
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
|
|
<meta name="format-detection" content="telephone=no">
|
2016-10-14 16:23:52 +08:00
|
|
|
|
2017-02-21 06:48:54 +08:00
|
|
|
<link rel="stylesheet" href="../src/css/layui.css">
|
2016-10-14 16:23:52 +08:00
|
|
|
|
|
|
|
<style>
|
|
|
|
body{padding: 10px;}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<form class="layui-form layui-form-pane1" action="">
|
|
|
|
<div class="layui-form-item">
|
|
|
|
<label class="layui-form-label">输入框</label>
|
|
|
|
<div class="layui-input-block">
|
2017-02-21 06:48:54 +08:00
|
|
|
<input type="text" name="title" lay-verify="required|title" required placeholder="请输入标题" autocomplete="off" class="layui-input">
|
2016-10-14 16:23:52 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="layui-form-item">
|
|
|
|
<label class="layui-form-label">手机</label>
|
|
|
|
<div class="layui-input-block">
|
2017-02-21 06:48:54 +08:00
|
|
|
<input type="tel" name="phone" lay-verify="phone" autocomplete="off" class="layui-input">
|
2016-10-14 16:23:52 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="layui-form-item">
|
|
|
|
<label class="layui-form-label">邮箱</label>
|
|
|
|
<div class="layui-input-block">
|
2017-02-21 06:48:54 +08:00
|
|
|
<input type="tel" name="email" lay-verify="email" autocomplete="off" class="layui-input">
|
2016-10-14 16:23:52 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="layui-form-item">
|
|
|
|
<label class="layui-form-label">密码</label>
|
|
|
|
<div class="layui-input-inline">
|
|
|
|
<input type="password" name="password" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
|
|
|
|
</div>
|
|
|
|
<div class="layui-form-mid layui-word-aux">请务必填写用户名</div>
|
|
|
|
</div>
|
|
|
|
<div class="layui-form-item">
|
|
|
|
<div class="layui-inline">
|
|
|
|
<label class="layui-form-label">范围</label>
|
|
|
|
<div class="layui-input-inline" style="width: 100px;">
|
|
|
|
<input type="text" name="price_min" placeholder="¥" autocomplete="off" class="layui-input">
|
|
|
|
</div>
|
|
|
|
<div class="layui-form-mid">-</div>
|
|
|
|
<div class="layui-input-inline" style="width: 100px;">
|
|
|
|
<input type="text" name="price_max" placeholder="¥" autocomplete="off" class="layui-input">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="layui-inline">
|
|
|
|
<label class="layui-form-label">行内表单</label>
|
|
|
|
<div class="layui-input-block">
|
|
|
|
<select name="quiz">
|
|
|
|
<option value="">请选择问题</option>
|
|
|
|
<option value="你工作的第一个城市">你工作的第一个城市</option>
|
2016-11-18 06:52:55 +08:00
|
|
|
<option value="你的工号" disabled>你的工号</option>
|
2016-10-14 16:23:52 +08:00
|
|
|
<option value="你最喜欢的老师">你最喜欢的老师</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-11-10 02:31:39 +08:00
|
|
|
<div class="layui-inline">
|
|
|
|
<label class="layui-form-label">select分组</label>
|
|
|
|
<div class="layui-input-block">
|
|
|
|
<select name="quiz">
|
|
|
|
<option value="">请选择问题</option>
|
|
|
|
<optgroup label="城市记忆">
|
|
|
|
<option value="你工作的第一个城市">你工作的第一个城市</option>
|
|
|
|
</optgroup>
|
|
|
|
<optgroup label="学生时代">
|
2016-11-18 06:52:55 +08:00
|
|
|
<option value="你的工号" disabled>你的工号</option>
|
2016-11-10 02:31:39 +08:00
|
|
|
<option value="你最喜欢的老师">你最喜欢的老师</option>
|
|
|
|
</optgroup>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2016-10-14 16:23:52 +08:00
|
|
|
</div>
|
2017-02-28 02:16:08 +08:00
|
|
|
|
2016-10-14 16:23:52 +08:00
|
|
|
<div class="layui-form-item">
|
|
|
|
<label class="layui-form-label">选择框</label>
|
|
|
|
<div class="layui-input-block">
|
|
|
|
<select name="interest" lay-filter="aihao">
|
|
|
|
<option value=""></option>
|
|
|
|
<option value="0">写作</option>
|
|
|
|
<option value="1" selected>阅读</option>
|
|
|
|
<option value="2">游戏</option>
|
|
|
|
<option value="3">音乐</option>
|
|
|
|
<option value="4">旅行</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-28 02:16:08 +08:00
|
|
|
|
|
|
|
<div class="layui-form-item">
|
|
|
|
<label class="layui-form-label">搜索选择框</label>
|
|
|
|
<div class="layui-input-inline">
|
|
|
|
<select name="interest" lay-filter="aihao" lay-search>
|
|
|
|
<option value=""></option>
|
|
|
|
<option value="0">写作</option>
|
|
|
|
<option value="1">阅读</option>
|
|
|
|
<option value="2">游戏</option>
|
|
|
|
<option value="3">音乐</option>
|
|
|
|
<option value="4">旅行</option>
|
|
|
|
<option value="5">读书</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2017-02-21 06:48:54 +08:00
|
|
|
<div class="layui-form-item" pane>
|
2016-10-14 16:23:52 +08:00
|
|
|
<label class="layui-form-label">复选框</label>
|
|
|
|
<div class="layui-input-block">
|
|
|
|
<input type="checkbox" name="like[write]" title="写作">
|
|
|
|
<input type="checkbox" name="like[read]" title="阅读">
|
2016-11-18 06:52:55 +08:00
|
|
|
<input type="checkbox" name="like[game]" title="游戏" disabled>
|
2016-10-14 16:23:52 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-28 02:16:08 +08:00
|
|
|
<div class="layui-form-item" pane>
|
|
|
|
<label class="layui-form-label">原始复选框</label>
|
|
|
|
<div class="layui-input-block">
|
|
|
|
<input type="checkbox" name="like1[write]" lay-skin="primary" title="写作">
|
|
|
|
<input type="checkbox" name="like1[read]" lay-skin="primary" title="阅读">
|
|
|
|
<input type="checkbox" name="like1[game]" lay-skin="primary" title="游戏" disabled>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-21 06:48:54 +08:00
|
|
|
<div class="layui-form-item" pane>
|
2016-10-14 16:23:52 +08:00
|
|
|
<label class="layui-form-label">开关关</label>
|
|
|
|
<div class="layui-input-block">
|
2017-02-28 02:16:08 +08:00
|
|
|
<input type="checkbox" name="close" lay-skin="switch" title="开关" disabled>
|
2016-10-14 16:23:52 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-21 06:48:54 +08:00
|
|
|
<div class="layui-form-item" pane>
|
2016-10-14 16:23:52 +08:00
|
|
|
<label class="layui-form-label">开关开</label>
|
|
|
|
<div class="layui-input-block">
|
2017-02-28 02:16:08 +08:00
|
|
|
<input type="checkbox" checked name="open" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
|
2016-10-14 16:23:52 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-21 06:48:54 +08:00
|
|
|
<div class="layui-form-item" pane>
|
2016-10-14 16:23:52 +08:00
|
|
|
<label class="layui-form-label">单选框</label>
|
|
|
|
<div class="layui-input-block">
|
|
|
|
<input type="radio" name="sex" value="男" title="男">
|
|
|
|
<input type="radio" name="sex" value="女" title="女" checked>
|
2016-11-18 06:52:55 +08:00
|
|
|
<input type="radio" name="sex" value="中型" title="中" disabled>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-02-21 06:48:54 +08:00
|
|
|
<div class="layui-form-item" pane>
|
2016-11-18 06:52:55 +08:00
|
|
|
<label class="layui-form-label">单选框</label>
|
|
|
|
<div class="layui-input-block">
|
|
|
|
<input type="radio" name="sex.id" value="男" title="男">
|
|
|
|
<input type="radio" name="sex.id" value="女" title="女" checked>
|
|
|
|
<input type="radio" name="sex.id" value="中型" title="中">
|
2016-10-14 16:23:52 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="layui-form-item layui-form-text">
|
|
|
|
<label class="layui-form-label">请填写描述</label>
|
|
|
|
<div class="layui-input-block">
|
|
|
|
<textarea placeholder="请输入内容" class="layui-textarea"></textarea>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="layui-form-item">
|
|
|
|
<div class="layui-input-block">
|
|
|
|
<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
|
|
|
|
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
2017-02-21 06:48:54 +08:00
|
|
|
<br><br><br>
|
2016-10-14 16:23:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
<script src="../src/layui.js"></script>
|
2016-11-30 02:23:57 +08:00
|
|
|
<!-- <script src="../build/lay/dest/layui.all.js"></script> -->
|
|
|
|
|
2016-10-14 16:23:52 +08:00
|
|
|
<script>
|
|
|
|
|
|
|
|
layui.use('form', function(){
|
|
|
|
var form = layui.form();
|
|
|
|
|
|
|
|
//自定义验证规则
|
|
|
|
form.verify({
|
|
|
|
title: function(value){
|
|
|
|
if(value.length < 5){
|
|
|
|
return '标题也太短了吧';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
,pass: [/(.+){6,12}$/, '密码必须6到12位']
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//事件监听
|
|
|
|
form.on('select', function(data){
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
form.on('select(aihao)', function(data){
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
form.on('checkbox', function(data){
|
|
|
|
console.log(data.elem.checked);
|
|
|
|
});
|
|
|
|
|
|
|
|
form.on('switch', function(data){
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
form.on('radio', function(data){
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
//监听提交
|
|
|
|
form.on('submit(*)', function(data){
|
|
|
|
console.log(data)
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<form id="test">
|
2016-11-18 06:52:55 +08:00
|
|
|
<input type="radio" value="girl" disabled>
|
2016-10-14 16:23:52 +08:00
|
|
|
<input type="checkbox" name="love[a]">
|
|
|
|
<input type="checkbox" name="love[b]">
|
|
|
|
<input value="1">
|
2016-11-18 06:52:55 +08:00
|
|
|
<select name="quiz">
|
|
|
|
<option value="">请选择问题</option>
|
|
|
|
<option disabled value="你工作的第一个城市">你工作的第一个城市</option>
|
|
|
|
<option value="你的工号">你的工号</option>
|
|
|
|
<option value="你最喜欢的老师">你最喜欢的老师</option>
|
|
|
|
</select>
|
2016-10-14 16:23:52 +08:00
|
|
|
<button>go</button>
|
|
|
|
</form>
|
|
|
|
<script>
|
|
|
|
layui.use('jquery', function(){
|
|
|
|
var $ = layui.jquery;
|
|
|
|
var submit = function(){
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
$('#test').on('submit', function(){
|
|
|
|
return false
|
|
|
|
});
|
|
|
|
$('#test').on('submit', function(){
|
|
|
|
return true
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|