forked from 275957304/edit_form
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsform.html
More file actions
96 lines (88 loc) · 3.29 KB
/
jsform.html
File metadata and controls
96 lines (88 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>表单</title>
<link rel="shortcut icon" href="/favicon.ico">
<link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
<script src="js/jquery.dad.js"></script>
</head>
<body class="gray-bg">
<div class="container">
<div class="row">
<div class="col-lg-3">
<div id="leftForm">
<h3 class="form-tit">通用字段</h3>
<div class="clearfix" id="col1">
<div data-type="text" class="btn-field"><span class="glyphicon glyphicon-text-width"></span>单行文本</div>
<div data-type="textarea" class="btn-field"><span class="glyphicon glyphicon-indent-right"></span>多行文本</div>
<div data-type="number" class="btn-field"><span class="glyphicon glyphicon-sound-6-1"></span>数字</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div id="middleForm">
<div id="fields">
</div>
</div>
</div>
<div class="col-lg-3">
<div id="rightForm">
fdsfsd
</div>
</div>
</div>
</div>
<script src="http://community.holichat.com/Public/Common/js/bootstrap.min.js?v=3.3.5"></script>
<script type="text/javascript">
$(function(){
$("#col1 .btn-field").on('click',function(){
var type = $(this).data('type');
switch(type){
case 'text' : form.text('text'); break;
case 'textarea' : form.textarea('textarea'); break;
case 'number' : form.number('number');; break;
default:
alert('没有找到');
}
})
var form = {
text : function(type){
var text = '<div data-type="'+ type +'" class="form-default"><div class="move"><label class="desc">单行文本<span class="req hide"> *</span></label><div class="content"><input type="text" /></div></div><span class="glyphicon glyphicon-plus"></span><span class="glyphicon glyphicon-minus"></span></div>';
$('#fields').append(text)
},
textarea : function(type){
var text = '<div data-type="'+ type +'" class="form-default"><div class="move"><label class="desc">多行文本<span class="req hide"> *</span></label><div class="content"><textarea class="input s"></textarea></div></div><span class="glyphicon glyphicon-plus"></span><span class="glyphicon glyphicon-minus"></span></div>';
$('#fields').append(text)
},
number : function(type){
var text = '<div data-type="'+ type +'" class="form-default"><div class="move"><label class="desc">数字<span class="req hide"> *</span></label><div class="content"><input type="text" /></div></div><span class="glyphicon glyphicon-plus"></span><span class="glyphicon glyphicon-minus"></span></div>';
$('#fields').append(text)
}
}
//增加
$('#fields').delegate('.glyphicon-plus','click',function(){
var html = $(this).parent().clone();
$(this).parent().after(html);
})
//删除
$('#fields').delegate('.glyphicon-minus','click',function(){
$(this).parent().remove();
})
$('#fields').dad({
draggable: '.move',
callback: function (e) {
var type = e.data('type');
createEdit(type)
}
});
function createEdit(type){
$('#rightForm').empty().append('这里生成' + type)
}
});
</script>
</body>
</html>