common.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. //解决 jquery Cannot read property 'msie' of undefined的问题
  2. jQuery.browser = {}; (function () { jQuery.browser.msie = false; jQuery.browser.version = 0; if (navigator.userAgent.match(/MSIE ([0-9]+)./)) { jQuery.browser.msie = true; jQuery.browser.version = RegExp.$1; } })();
  3. // 获取路由参数 name:参数名
  4. function getUrlOption(name) {
  5. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  6. var r = window.location.search.substr(1).match(reg);
  7. if (r != null) return decodeURI(r[2]); return null;
  8. }
  9. function showErrorMsg(d) {
  10. //d = JSON.parse(d);
  11. if (d.Ret == -1001001)
  12. window.location.href = "/Error/Msg?code=1&msg=" + d.msg + "&url=/";
  13. else {
  14. //$.messager.alert("提示", d.Msg);
  15. layer.alert(d.Msg, { icon: 6 });
  16. }
  17. }
  18. //实现页面不跳转
  19. function formResult(tagForm, isAlert, funcall, successMsg, goUrl) {
  20. $("#" + tagForm + " button[class='btn btn-success']").attr("disabled", true);
  21. $("#" + tagForm).ajaxSubmit({
  22. success: function (data) {
  23. var flag = isJsonString(data);
  24. if (flag)
  25. data = JSON.parse(data);
  26. if (data.Ret == 0) {
  27. if (isAlert) {
  28. if (successMsg)
  29. {
  30. layer.msg(successMsg, { icon: 1 });
  31. //$.messager.alert("提示", successMsg);
  32. }
  33. else
  34. {
  35. layer.msg('操作成功', { icon: 1 });
  36. //$.messager.alert("提示", "操作成功");
  37. }
  38. if (funcall != null)
  39. {
  40. funcall();
  41. }
  42. if (goUrl) {
  43. setTimeout(function () {
  44. location.href = goUrl;
  45. }, 2000);
  46. }
  47. } else {
  48. if (goUrl) {
  49. setTimeout(function () {
  50. location.href = goUrl;
  51. }, 2000);
  52. }
  53. }
  54. $("#" + tagForm + " button[class='btn btn-success']").removeAttr("disabled");
  55. }
  56. else {
  57. showErrorMsg(data);
  58. $("#" + tagForm + " button[class='btn btn-success']").removeAttr("disabled");
  59. }
  60. },
  61. error: function () {
  62. $("#" + tagForm + " button[class='btn btn-success']").removeAttr("disabled");
  63. }
  64. });
  65. }
  66. function FunDo(url, paras) {
  67. $.post(url, paras, function (data) {
  68. if (data.Ret == 0) {
  69. layer.msg('操作成功', { icon: 1 });
  70. //$.messager.alert("提示", "操作成功");
  71. //setTimeout(function () {
  72. // location.reload();
  73. //}, 1000);
  74. }
  75. else {
  76. layer.alert(d.Msg, { icon: 6 });
  77. //$.messager.alert("提示", data.Msg);
  78. }
  79. });
  80. }
  81. function isJsonString(str) {
  82. try {
  83. if (typeof JSON.parse(str) == "object") {
  84. return true;
  85. }
  86. } catch (e) {
  87. }
  88. return false;
  89. }
  90. var telPhoneRegex = /^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$/;
  91. var mobilePhoneRegex = /^[1][3,4,5,7,8][0-9]{9}$/;
  92. var emailRegex = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
  93. var idCardRegex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
  94. function FunEdit(url) {
  95. var rows = $('#Ctr_DataGrid').datagrid('getSelected');
  96. if (!rows) {
  97. layer.alert("修改时,请选择一行需要【修改】的数据", { icon: 6 });
  98. //$.messager.alert("提示", "修改时,请选择一行需要【修改】的数据");
  99. return false;
  100. }
  101. var idEdit = rows.Id;
  102. window.location.href = url + "?id=" + idEdit;
  103. }
  104. //删除
  105. function FunDelete(url) {
  106. var rows = $('#Ctr_DataGrid').datagrid('getSelected');
  107. if (!rows) {
  108. layer.alert("删除时,请选择一行需要【删除】的数据", { icon: 6 });
  109. return false;
  110. }
  111. var IdDel = rows.Id;
  112. layer.confirm('您确定要删除吗?', {
  113. icon: 4,
  114. title: '提示' //按钮
  115. }, function () {
  116. $.post(url,
  117. {
  118. id: IdDel
  119. },
  120. function (data) {
  121. if (data.Ret == 0) {
  122. layer.msg("删除成功", { icon: 1 });
  123. FunRefresh();
  124. } else {
  125. layer.alert(data.Msg, { icon: 6 });
  126. }
  127. }, "json");
  128. });
  129. }
  130. $(function () {
  131. $(".onlyNum_one").keyup(function () {
  132. var tmptxt = $(this).val();
  133. if ($(this).val() == "-1") {
  134. var $input = $('input:text:not(:disabled)');
  135. var n = $input.length;
  136. var nextIndex = $input.index(this) + 1;
  137. if (nextIndex < n) {
  138. $input[nextIndex].focus();
  139. $input[nextIndex].select()
  140. }
  141. else {
  142. $input[nextIndex - 1].blur();
  143. $input[nextIndex - 1].select()
  144. }
  145. return;
  146. }
  147. if (tmptxt.length >= 1 ) {
  148. tmptxt = tmptxt.substring(1, 0);
  149. }
  150. $(this).val(tmptxt.replace(/[^-0-9]/g, ''));
  151. if ($(this).val() < 9)
  152. {
  153. var $input = $('input:text:not(:disabled)');
  154. var n = $input.length;
  155. var nextIndex = $input.index(this) + 1;
  156. if (nextIndex < n) {
  157. $input[nextIndex].focus();
  158. $input[nextIndex].select()
  159. }
  160. else {
  161. $input[nextIndex - 1].blur();
  162. $input[nextIndex - 1].select()
  163. }
  164. }
  165. }).bind("paste", function () {
  166. var tmptxt = $(this).val();
  167. $(this).val(tmptxt.replace(/\D|^/g, ''));
  168. })
  169. $(".onlyNum_two").keyup(function () {
  170. var tmptxt = $(this).val();
  171. if (tmptxt.length >= 2) {
  172. tmptxt = tmptxt.substring(2, 0);
  173. }
  174. $(this).val(tmptxt.replace(/\D|^0/g, ''));
  175. if ($(this).val().length >= 2) {
  176. var $input = $('input:text:not(:disabled)');
  177. var n = $input.length;
  178. var nextIndex = $input.index(this) + 1;
  179. if (nextIndex < n) {
  180. $input[nextIndex].focus();
  181. $input[nextIndex].select()
  182. }
  183. else {
  184. $input[nextIndex - 1].blur();
  185. $input[nextIndex - 1].select()
  186. }
  187. }
  188. }).bind("paste", function () {
  189. var tmptxt = $(this).val();
  190. $(this).val(tmptxt.replace(/\D|^0/g, ''));
  191. })
  192. $(".onlyNum_two_qlc").keyup(function () {
  193. var tmptxt = $(this).val();
  194. if (tmptxt > 30)
  195. tmptxt = tmptxt.substring(1, 0);
  196. if (tmptxt.length >= 2) {
  197. tmptxt = tmptxt.substring(2, 0);
  198. }
  199. $(this).val(tmptxt.replace(/\D|^/g, ''));
  200. if ($(this).val().length >= 2) {
  201. var $input = $('input:text:not(:disabled)');
  202. var n = $input.length;
  203. var nextIndex = $input.index(this) + 1;
  204. if (nextIndex < n) {
  205. $input[nextIndex].focus();
  206. $input[nextIndex].select()
  207. }
  208. else {
  209. $input[nextIndex - 1].blur();
  210. $input[nextIndex - 1].select()
  211. }
  212. }
  213. }).bind("paste", function () {
  214. var tmptxt = $(this).val();
  215. $(this).val(tmptxt.replace(/\D|^0/g, ''));
  216. })
  217. $(".onlyNum_two_16").keyup(function () {
  218. var tmptxt = $(this).val();
  219. if ($(this).val() == "-1") {
  220. var $input = $('input:text:not(:disabled)');
  221. var n = $input.length;
  222. var nextIndex = $input.index(this) + 1;
  223. if (nextIndex < n) {
  224. $input[nextIndex].focus();
  225. $input[nextIndex].select()
  226. }
  227. else {
  228. $input[nextIndex - 1].blur();
  229. $input[nextIndex - 1].select()
  230. }
  231. return;
  232. }
  233. if (tmptxt > 16)
  234. tmptxt = tmptxt.substring(1, 0);
  235. if (tmptxt.length >= 2) {
  236. tmptxt = tmptxt.substring(2, 0);
  237. }
  238. $(this).val(tmptxt.replace(/[^-0-9]/g, ''));
  239. if ($(this).val().length >= 2) {
  240. var $input = $('input:text:not(:disabled)');
  241. var n = $input.length;
  242. var nextIndex = $input.index(this) + 1;
  243. if (nextIndex < n) {
  244. $input[nextIndex].focus();
  245. $input[nextIndex].select()
  246. }
  247. else {
  248. $input[nextIndex - 1].blur();
  249. $input[nextIndex - 1].select()
  250. }
  251. }
  252. }).bind("paste", function () {
  253. var tmptxt = $(this).val();
  254. $(this).val(tmptxt.replace(/\D|^0/g, ''));
  255. })
  256. $(".onlyNum_two_33").keyup(function () {
  257. var tmptxt = $(this).val();
  258. if ($(this).val() == "-1") {
  259. var $input = $('input:text:not(:disabled)');
  260. var n = $input.length;
  261. var nextIndex = $input.index(this) + 1;
  262. if (nextIndex < n) {
  263. $input[nextIndex].focus();
  264. $input[nextIndex].select()
  265. }
  266. else {
  267. $input[nextIndex - 1].blur();
  268. $input[nextIndex - 1].select()
  269. }
  270. return;
  271. }
  272. if (tmptxt > 33)
  273. tmptxt = tmptxt.substring(1, 0);
  274. if (tmptxt.length >= 2) {
  275. tmptxt = tmptxt.substring(2, 0);
  276. }
  277. $(this).val(tmptxt.replace(/[^-0-9]/g, ''));
  278. if ($(this).val().length >= 2) {
  279. var $input = $('input:text:not(:disabled)');
  280. var n = $input.length;
  281. var nextIndex = $input.index(this) + 1;
  282. if (nextIndex < n) {
  283. $input[nextIndex].focus();
  284. $input[nextIndex].select()
  285. }
  286. else {
  287. $input[nextIndex - 1].blur();
  288. $input[nextIndex - 1].select()
  289. }
  290. }
  291. }).bind("paste", function () {
  292. var tmptxt = $(this).val();
  293. $(this).val(tmptxt.replace(/\D|^0/g, ''));
  294. })
  295. $(".onlyNum_two_35").keyup(function () {
  296. var tmptxt = $(this).val();
  297. if (tmptxt > 35)
  298. tmptxt = tmptxt.substring(1, 0);
  299. if (tmptxt.length >= 2) {
  300. tmptxt = tmptxt.substring(2, 0);
  301. }
  302. $(this).val(tmptxt.replace(/\D|^/g, ''));
  303. if ($(this).val().length >= 2) {
  304. var $input = $('input:text:not(:disabled)');
  305. var n = $input.length;
  306. var nextIndex = $input.index(this) + 1;
  307. if (nextIndex < n) {
  308. $input[nextIndex].focus();
  309. $input[nextIndex].select()
  310. }
  311. else {
  312. $input[nextIndex - 1].blur();
  313. $input[nextIndex - 1].select()
  314. }
  315. }
  316. }).bind("paste", function () {
  317. var tmptxt = $(this).val();
  318. $(this).val(tmptxt.replace(/\D|^0/g, ''));
  319. })
  320. $(".onlyNum_two_12").keyup(function () {
  321. var tmptxt = $(this).val();
  322. if (tmptxt > 12)
  323. tmptxt = tmptxt.substring(1, 0);
  324. if (tmptxt.length >= 2) {
  325. tmptxt = tmptxt.substring(2, 0);
  326. }
  327. $(this).val(tmptxt.replace(/\D|^/g, ''));
  328. if ($(this).val().length >= 2) {
  329. var $input = $('input:text:not(:disabled)');
  330. var n = $input.length;
  331. var nextIndex = $input.index(this) + 1;
  332. if (nextIndex < n) {
  333. $input[nextIndex].focus();
  334. $input[nextIndex].select()
  335. }
  336. else {
  337. $input[nextIndex - 1].blur();
  338. $input[nextIndex - 1].select()
  339. }
  340. }
  341. }).bind("paste", function () {
  342. var tmptxt = $(this).val();
  343. $(this).val(tmptxt.replace(/\D|^0/g, ''));
  344. })
  345. })