validator.common.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. var Browser = new Object();
  2. Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument != 'undefined');
  3. Browser.isIE = window.ActiveXObject ? true : false;
  4. Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox") != -1);
  5. Browser.isSafari = (navigator.userAgent.toLowerCase().indexOf("safari") != -1);
  6. Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
  7. var Common = new Object();
  8. Common.htmlEncode = function(str) {
  9. return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  10. }
  11. Common.trim = function(str) {
  12. return str.replace(/(^\s*)|(\s*$)/g, "");
  13. }
  14. Common.strlen = function(str) {
  15. if (Browser.isFirefox) {
  16. Charset = document.characterSet;
  17. } else {
  18. Charset = document.charset;
  19. }
  20. if (Charset.toLowerCase() == 'utf-8') {
  21. return str.replace(/[\u4e00-\u9fa5]/g, "***").length;
  22. } else {
  23. return str.replace(/[^\x00-\xff]/g, "**").length;
  24. }
  25. }
  26. Common.isdate = function(str) {
  27. var result = str.match(/^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
  28. if (result == null) return false;
  29. var d = new Date(result[1], result[3] - 1, result[4]);
  30. return (d.getFullYear() == result[1] && d.getMonth() + 1 == result[3] && d.getDate() == result[4]);
  31. }
  32. Common.isnumber = function(val) {
  33. var reg = /[\d|\.|,]+/;
  34. return reg.test(val);
  35. }
  36. Common.isalphanumber = function(str) {
  37. var result = str.match(/^[a-zA-Z0-9]+$/);
  38. if (result == null) return false;
  39. return true;
  40. }
  41. Common.isint = function(val) {
  42. var reg = /\d+/;
  43. return reg.test(val);
  44. }
  45. Common.isemail = function(email) {
  46. var reg = /([\w|_|\.|\+]+)@([-|\w]+)\.([A-Za-z]{2,4})/;
  47. return reg.test(email);
  48. }
  49. Common.fixeventargs = function(e) {
  50. var evt = (typeof e == "undefined") ? window.event : e;
  51. return evt;
  52. }
  53. Common.srcelement = function(e) {
  54. if (typeof e == "undefined") e = window.event;
  55. var src = document.all ? e.srcElement : e.target;
  56. return src;
  57. }
  58. Common.isdatetime = function(val) {
  59. var result = str.match(/^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
  60. if (result == null) return false;
  61. var d = new Date(result[1], result[3] - 1, result[4], result[5], result[6], result[7]);
  62. return (d.getFullYear() == result[1] && (d.getMonth() + 1) == result[3] && d.getDate() == result[4] && d.getHours() == result[5] && d.getMinutes() == result[6] && d.getSeconds() == result[7]);
  63. }
  64. var FileNum = 1;
  65. function AddInputFile(Field) {
  66. FileNum++;
  67. var fileTag = "<div id='file_" + FileNum + "'><input type='file' name='" + Field + "[" + FileNum + "]' size='20' onchange='javascript:AddInputFile(\"" + Field + "\")'> <input type='text' name='" + Field + "_description[" + FileNum + "]' size='20' title='名称'> <input type='button' value='删除' name='Del' onClick='DelInputFile(" + FileNum + ");'></div>";
  68. var fileObj = document.createElement("div");
  69. fileObj.id = 'file_' + FileNum;
  70. fileObj.innerHTML = fileTag;
  71. document.getElementById("file_div").appendChild(fileObj);
  72. }
  73. function DelInputFile(FileNum) {
  74. var DelObj = document.getElementById("file_" + FileNum);
  75. document.getElementById("file_div").removeChild(DelObj);
  76. }
  77. function FilePreview(Url, IsShow) {
  78. Obj = document.getElementById('FilePreview');
  79. if (IsShow) {
  80. Obj.style.left = event.clientX + 80;
  81. Obj.style.top = event.clientY + 20;
  82. Obj.innerHTML = "<img src='" + Url + "'>";
  83. Obj.style.display = 'block';
  84. } else {
  85. Obj.style.display = 'none';
  86. }
  87. }
  88. function setEditorSize(editorID, flag) {
  89. var minHeight = 400;
  90. var step = 150;
  91. var e = $('#' + editorID);
  92. var h = parseInt(e.height());
  93. if (!flag && h < minHeight) {
  94. e.height(200);
  95. return;
  96. }
  97. return flag ? (e.height(h + step)) : (e.height(h - step));
  98. }
  99. function EditorSize(editorID) {
  100. $('a[action]').parent('div').css({
  101. 'text-align': 'right'
  102. });
  103. $('a[action]').css({
  104. 'font-size': '24px',
  105. 'font-weight': 700,
  106. display: 'block',
  107. float: 'right',
  108. width: '28px',
  109. 'text-align': 'center'
  110. });
  111. $('a[action]').click(function() {
  112. var flag = parseInt($(this).attr('action'));
  113. setEditorSize(editorID, flag);
  114. });
  115. }
  116. function modal(url, triggerid, id, type) {
  117. id = '#' + id;
  118. triggerid = '#' + triggerid;
  119. switch (type) {
  120. case 'ajax':
  121. $(id).jqm({
  122. ajax: url,
  123. modal: false,
  124. trigger: triggerid
  125. });
  126. break;
  127. default:
  128. $(id).jqm();
  129. break;
  130. }
  131. $(id).html('');
  132. $(id).hide();
  133. }
  134. function menu_selected(id) {
  135. $('#menu_' + id).addClass('selected');
  136. }
  137. function is_ie() {
  138. if (!$.browser.msie) {
  139. $("body").prepend('<div id="MM_msie" style="border:#FF7300 solid 1px;padding:10px;color:#FF0000">本功能只支持IE浏览器,请用IE浏览器打开。<div>');
  140. }
  141. }
  142. function select_catids() {
  143. $('#addbutton').attr('disabled', '');
  144. }
  145. function transact(update, fromfiled, tofiled) {
  146. if (update == 'delete') {
  147. var fieldvalue = $('#' + tofiled).val();
  148. $("select[@id=" + tofiled + "] option").each(function() {
  149. if ($(this).val() == fieldvalue) {
  150. $(this).remove();
  151. }
  152. });
  153. } else {
  154. var fieldvalue = $('#' + fromfiled).val();
  155. var have_exists = 0;
  156. var len = $("select[@id=" + tofiled + "] option").length;
  157. if (len > 5) {
  158. alert('最多添加 6 项');
  159. return false;
  160. }
  161. $("select[@id=" + tofiled + "] option").each(function() {
  162. if ($(this).val() == fieldvalue) {
  163. have_exists = 1;
  164. alert('已经添加到列表中');
  165. return false;
  166. }
  167. });
  168. if (have_exists == 0) {
  169. fieldvalue = "<option value='" + fieldvalue + "'>" + fieldvalue + "</option>"
  170. $('#' + tofiled).append(fieldvalue);
  171. $('#deletebutton').attr('disabled', '');
  172. }
  173. }
  174. }
  175. var set_show = false;