layui.define(['layer', 'form'], function(exports) { var layer = layui.layer, form = layui.form, $ = layui.$, key = ''; delHtml() $('button').on('click', function() { var _this = $(this), size = _this.data('size'), type = _this.data('type'), html = ''; key = randStrName(); switch (type) { case 'text': html = input(type, size) break; case 'password': html = input(type, size) break; case 'select': html = select(size) break; case 'checkbox_a': html = checkbox_a(size) break; case 'checkbox_b': html = checkbox_b(size) break; case 'radio': html = radio(size) break; case 'textarea': html = textarea(size) break; case 'submit': html = submits(size) break; case 'del': $('form').html("\n") delHtml() $('.code-show').text('') return false break; default: layer.msg('类型错误', { icon: 2 }) } $('form').append(html); form.render(); setHtml(html) }) function delHtml() { layui.data('form_html', { key: 'html', remove: true }); } function setHtml(html) { var h = layui.data('form_html'); if (h && h.html) { var _d = h.html + html } else { var _d = html } layui.data('form_html', { key: 'html', value: _d }) $('.code-show').text('
') } function input(type, size) { var name = type === 'text' ? '输入框' : (type === 'password' ? '密码框' : ''); var html = '