content_edit.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. $(function () {
  2. var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
  3. var isOpera = userAgent.indexOf("Opera") > -1;
  4. console.log(3);
  5. if (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera) {
  6. console.log(1);
  7. debugger
  8. $("#create_time").remove();
  9. } else {
  10. console.log(2);
  11. $("#create_timeIE").remove();
  12. var startDate = laydate.render({
  13. elem: '#create_time',
  14. type: 'datetime',
  15. done: function (value, date) {
  16. setTimeout(function () {
  17. $("#form-content-edit").validate().element($("#create_time"));
  18. }, 100)
  19. }
  20. });
  21. }
  22. $("#form-content-edit").validate({
  23. rules: {
  24. title: {
  25. required: true,
  26. minlength: 1,
  27. maxlength: 64
  28. },
  29. navigation_id: {
  30. required: true,
  31. },
  32. content: {
  33. required: true,
  34. },
  35. resource: {
  36. // required: true,
  37. minlength: 1,
  38. maxlength: 64
  39. },
  40. sort: {
  41. required: true,
  42. min: 0,
  43. max: 10000,
  44. digits: true
  45. },
  46. brief: {
  47. // // required: true,
  48. // maxlength: 100
  49. }
  50. },
  51. onkeyup:false,
  52. focusCleanup:true,
  53. success:"valid",
  54. submitHandler:function(form){
  55. //如果摘要没填写,取正文前50个字
  56. //2018-07-06 不需要自动加摘要
  57. /*if($.trim($("#brief").val())==""){
  58. var content = $("#content").val();
  59. if($.trim(content)!=""){
  60. var defaultAbstract = "";
  61. //去除标签
  62. var cleanContent = content.replace(/<\/?.+?>/g,""); //去标签
  63. cleanContent = cleanContent.replace(/(^\s+)|(\s+$)/g,""); //去空格
  64. cleanContent = cleanContent.replace(/(\r)|(\n)/g,""); //去回车
  65. cleanContent = cleanContent.replace(/&nbsp;/ig,''); //去掉&nbsp;
  66. if(cleanContent.length>50){
  67. defaultAbstract = cleanContent.substring(0,50);
  68. defaultAbstract += "...";
  69. }else{
  70. defaultAbstract = cleanContent;
  71. }
  72. $("#brief").val(defaultAbstract);
  73. }
  74. }*/
  75. $(form).ajaxSubmit({
  76. type: 'PUT',
  77. url: pagePath+"/government/content/update/"+$("#content_id").val(),
  78. dataType:"json",
  79. success: function(data){
  80. if(data.status == "success"){
  81. succeedMessage(data.message);
  82. setTimeClose();
  83. }else {
  84. errorMessage(data.message);
  85. }
  86. }
  87. });
  88. return false; // 非常重要,如果是false,则表明是不跳转,在本页上处理,也就是ajax,如果是非false,则传统的form跳转。
  89. },
  90. errorPlacement: function(error, element) {
  91. if(element.attr('id') == 'content'){
  92. error.addClass(' label_error')
  93. }
  94. error.appendTo(element.parent());
  95. }
  96. });
  97. });