add.html 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <style>
  2. .nav-title{
  3. display: none;
  4. }
  5. </style>
  6. <div style="margin:50px auto;width: 400px;">
  7. <form class="layui-form" action="" method="post" >
  8. <div class="layui-form-item">
  9. <label class="layui-form-label">选择分组</label>
  10. <div class="layui-input-inline">
  11. <select name="group_id" lay-verify="required" lay-search="" style="width: 100%">
  12. <option value="">请选择分组</option>
  13. {{range $index,$elem := .Groups}}
  14. <option value="{{$elem.id}}">{{$elem.group_name}}</option>
  15. {{end}}
  16. </select>
  17. </div>
  18. <div class="layui-form-mid layui-word-aux">*</div>
  19. </div>
  20. <div class="layui-form-item">
  21. <label class="layui-form-label">资源名称</label>
  22. <div class="layui-input-inline">
  23. <input type="text" name="source_name" id="source_name" lay-verify="required" autocomplete="off" placeholder="资源名称" class="layui-input" value="">
  24. </div>
  25. <div class="layui-form-mid layui-word-aux">*</div>
  26. </div>
  27. <div class="layui-form-item">
  28. <div class="layui-input-block">
  29. <button class="layui-btn" lay-submit="" lay-filter="sub">保存</button>
  30. <button type="reset" class="layui-btn layui-btn-primary">重置</button>
  31. </div>
  32. </div>
  33. </form>
  34. </div>
  35. <script>
  36. var $;
  37. layui.config({
  38. base : "js/"
  39. }).use(['form','element','layer','jquery'],function(){
  40. var form = layui.form; //只有执行了这一步,部分表单元素才会自动修饰成功
  41. var $ = layui.jquery;
  42. form.on('submit(sub)', function(data){
  43. var form_data = data.field;
  44. $.post('{{urlfor "ApiSourceController.AjaxSave"}}', form_data, function (out) {
  45. if (out.status == 0) {
  46. layer.msg("操作成功",{icon: 1},function () {
  47. window.parent.layer.closeAll();
  48. window.parent.location.reload();
  49. })
  50. } else {
  51. layer.msg(out.message)
  52. }
  53. }, "json");
  54. return false;
  55. });
  56. //但是,如果你的HTML是动态生成的,自动渲染就会失效
  57. //因此你需要在相应的地方,执行下述方法来手动渲染,跟这类似的还有 element.init();
  58. form.render();
  59. });
  60. </script>