add.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. $().ready(function() {
  2. validateRule();
  3. });
  4. $.validator.setDefaults({
  5. submitHandler : function() {
  6. save();
  7. }
  8. });
  9. function save() {
  10. $.ajax({
  11. cache : true,
  12. type : "POST",
  13. url : "/datas/dataPart/save",
  14. data : $('#signupForm').serialize(),// 你的formid
  15. async : false,
  16. error : function(request) {
  17. parent.layer.alert("Connection error");
  18. },
  19. success : function(data) {
  20. if (data.code == 0) {
  21. parent.layer.msg("操作成功");
  22. parent.reLoad();
  23. var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
  24. parent.layer.close(index);
  25. } else {
  26. parent.layer.alert(data.msg)
  27. }
  28. }
  29. });
  30. }
  31. function validateRule() {
  32. var icon = "<i class='fa fa-times-circle'></i> ";
  33. $("#signupForm").validate({
  34. rules : {
  35. name : {
  36. required: true
  37. }
  38. },
  39. messages: {
  40. name: {
  41. required: icon + "请输入姓名"
  42. }
  43. }
  44. })
  45. }
  46. //返回
  47. $("#go_back").click(function () {
  48. var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
  49. parent.layer.close(index);
  50. });