login.1.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. $(function(){
  2. // 复选框
  3. $('input').iCheck({
  4. checkboxClass: 'icheckbox_square-blue',
  5. radioClass: 'iradio_square-blue',
  6. increaseArea: '20%' // optional
  7. });
  8. // 登录.规则校验
  9. var loginFormValid = $("#loginForm").validate({
  10. errorElement : 'span',
  11. errorClass : 'help-block',
  12. focusInvalid : true,
  13. rules : {
  14. userName : {
  15. required : true ,
  16. minlength: 5,
  17. maxlength: 18
  18. },
  19. password : {
  20. required : true ,
  21. minlength: 5,
  22. maxlength: 18
  23. }
  24. },
  25. messages : {
  26. userName : {
  27. required :"请输入登录账号." ,
  28. minlength:"登录账号不应低于5位",
  29. maxlength:"登录账号不应超过18位"
  30. },
  31. password : {
  32. required :"请输入登录密码." ,
  33. minlength:"登录密码不应低于5位",
  34. maxlength:"登录密码不应超过18位"
  35. }
  36. },
  37. highlight : function(element) {
  38. $(element).closest('.form-group').addClass('has-error');
  39. },
  40. success : function(label) {
  41. label.closest('.form-group').removeClass('has-error');
  42. label.remove();
  43. },
  44. errorPlacement : function(error, element) {
  45. element.parent('div').append(error);
  46. },
  47. submitHandler : function(form) {
  48. $.post(base_url + "/login", $("#loginForm").serialize(), function(data, status) {
  49. if (data.code == "200") {
  50. layer.msg('登录成功');
  51. setTimeout(function(){
  52. window.location.href = base_url;
  53. }, 500);
  54. /*layer.open({
  55. title: '系统提示',
  56. content: '登录成功',
  57. icon: '1',
  58. end: function(layero, index){
  59. window.location.href = base_url;
  60. }
  61. });*/
  62. } else {
  63. layer.open({
  64. title: '系统提示',
  65. content: (data.msg || "登录失败"),
  66. icon: '2'
  67. });
  68. }
  69. });
  70. }
  71. });
  72. });