tools.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. function winOpen (strURL,strName,width,height)
  2. {
  3. theWindow = window.open (strURL,strName,"width="+width+" height="+height+" scrollbars=yes left="+(1024-width)/2+" top="+(768-height)/2);
  4. if (theWindow.opener == null) theWindow.opener = window;
  5. if (window.focus) theWindow.focus();
  6. }
  7. //验证邮件
  8. function verifyEmailAddress(strEmail){
  9. var myReg = /^[_a-zA-Z0-9_-_._-]+@([_a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,3}$/;
  10. return myReg.test(strEmail);
  11. }
  12. /*****************************************************************
  13. **** 判断是否为日期数据 (lhm) 例子:itIsDate("2009-10-7" , "-") *****
  14. *****************************************************************/
  15. function itIsDate(DateString , Dilimeter)
  16. {
  17. if (DateString==null) return false;
  18. if (Dilimeter=='' || Dilimeter==null)
  19. Dilimeter = '-';
  20. var tempy='';
  21. var tempm='';
  22. var tempd='';
  23. var tempArray;
  24. if (DateString.length<8 && DateString.length>10)
  25. return false;
  26. tempArray = DateString.split(Dilimeter);
  27. if (tempArray.length!=3)
  28. return false;
  29. if (tempArray[0].length==4)
  30. {
  31. tempy = tempArray[0];
  32. tempd = tempArray[2];
  33. }
  34. else
  35. {
  36. tempy = tempArray[2];
  37. tempd = tempArray[1];
  38. }
  39. tempm = tempArray[1];
  40. var tDateString = tempy + '/'+tempm + '/'+tempd+' 8:0:0';//加八小时是因为我们处于东八区
  41. var tempDate = new Date(tDateString);
  42. if (isNaN(tempDate))
  43. return false;
  44. if (((tempDate.getUTCFullYear()).toString()==tempy) && (tempDate.getMonth()==parseInt(tempm)-1) && (tempDate.getDate()==parseInt(tempd)))
  45. {
  46. return true;
  47. }
  48. else
  49. {
  50. return false;
  51. }
  52. }
  53. /*****************************************************************
  54. **** 求字符串的字节长度 (lhm) *****
  55. *****************************************************************/
  56. function byteLength(paraString)
  57. {
  58. var strValue =new String(paraString);
  59. var strLength = strValue.length;
  60. var numLength =0;
  61. for (globle_i =0 ; globle_i<strLength;globle_i++){
  62. var ASCIIValue =strValue.charCodeAt(globle_i);
  63. if ( ASCIIValue > 0 && ASCIIValue < 127 )
  64. numLength = numLength + 1
  65. else
  66. numLength = numLength + 2
  67. }
  68. return numLength;
  69. }
  70. /*****************************************************************
  71. **** 去除空格 (lhm) *****
  72. *****************************************************************/
  73. function trim(stringToTrim) {
  74. return stringToTrim.replace(/^\s+|\s+$/g,"");
  75. }
  76. function ltrim(stringToTrim) {
  77. return stringToTrim.replace(/^\s+/,"");
  78. }
  79. function rtrim(stringToTrim) {
  80. return stringToTrim.replace(/\s+$/,"");
  81. }
  82. String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g,"");}
  83. String.prototype.ltrim = function() {return this.replace(/^\s+/,"");}
  84. String.prototype.rtrim = function() {return this.replace(/\s+$/,"");}
  85. /*****************************************************************
  86. **** 复选框的全选与取消 (LHM) *****
  87. *****************************************************************/
  88. function CheckAll(form){
  89. var length = form.itemId.length;
  90. var tocheck = form.chkall.checked;
  91. if (length)
  92. for (var i=0; i<length; i++){
  93. if (form.itemId[i].disabled != true){
  94. form.itemId[i].checked = tocheck;
  95. }
  96. }
  97. else {
  98. if (form.itemId.disabled !=true){
  99. form.itemId.checked = tocheck;
  100. }
  101. }
  102. }
  103. /*****************************************************************
  104. **** 删除处理 (LHM) *****
  105. *****************************************************************/
  106. function del_btn (form,strMsg,actionurl){
  107. var result = false;
  108. var length = form.itemId.length;
  109. if (form.itemId.checked) { //只有一条记录时执行此语句
  110. result = true;
  111. }
  112. for (var i=0; i<length; i++){
  113. if (form.itemId[i].checked){
  114. result = true;
  115. break;
  116. }
  117. }
  118. if (!result){
  119. alert ("没有选择任何项目!");
  120. return false;
  121. }else{
  122. if (confirm('\n'+strMsg)){
  123. form.action = actionurl;
  124. return true;
  125. }
  126. return false;
  127. }
  128. }
  129. /*****************************************************************
  130. **** 转化字符串 (LHM) *****
  131. *****************************************************************/
  132. function conversion_code(paraString)
  133. {
  134. strResult = "";
  135. j=0;
  136. for (i=0;i<paraString.length;i++){
  137. Char = String1.charAt(i);
  138. if (Char=="'"){
  139. strResult = strResult + paraString.substring(j,i)+"\\"+"\'";
  140. j=i+1;
  141. }
  142. return strResult;
  143. }
  144. }
  145. /*****************************************************************
  146. **** 数字输入控制处理 (LHM) *****
  147. *****************************************************************/
  148. function InputIntNumberCheck(){
  149. //为支持IE 或 Netscape
  150. var theEvent=window.event || arguments.callee.caller.arguments[0];
  151. var elm ;
  152. var ver = navigator.appVersion;
  153. if (ver.indexOf("MSIE") != -1){ // IE
  154. if ( !((theEvent.keyCode >=48)&&(theEvent.keyCode<=57))){
  155. theEvent.keyCode=0;
  156. }
  157. }else{ // Netscape
  158. if ( !((theEvent.which >=48)&&(theEvent.which<=57))){
  159. theEvent.stopPropagation();
  160. theEvent.preventDefault();
  161. }
  162. }
  163. //
  164. }
  165. /*****************************************************************
  166. **** 有小数点数字输入控制处理 (LHM) *****
  167. *****************************************************************/
  168. function InputLongNumberCheck(){
  169. if ( !((window.event.keyCode >=48)&&(window.event.keyCode<=57) || window.event.keyCode ==46)){
  170. window.event.keyCode=0;
  171. }
  172. var theEvent=window.event || arguments.callee.caller.arguments[0];
  173. var elm ;
  174. var ver = navigator.appVersion;
  175. if (ver.indexOf("MSIE") != -1){ // IE
  176. if (!((theEvent.keyCode>=48)&&(theEvent.keyCode<=57) || theEvent.keyCode ==46)){
  177. theEvent.keyCode=0;
  178. }
  179. }else{ // Netscape
  180. if ( !((theEvent.which >=48)&&(theEvent.which<=57) || theEvent.which ==46)){
  181. theEvent.stopPropagation();
  182. theEvent.preventDefault();
  183. }
  184. }
  185. }
  186. /*****************************************************************
  187. **** 换页处理 *****
  188. *****************************************************************/
  189. function toWhichPage(objform, whichPage){
  190. objform.whichPage.value = whichPage;
  191. objform.submit();
  192. }
  193. /*************************liuxch *******************************
  194. **** 获取cookie内容 *****
  195. *****************************************************************/
  196. function getCookie( name ){
  197. var nameOfCookie = name + "=";
  198. var x = 0;
  199. while ( x <= document.cookie.length ){
  200. var y = (x+nameOfCookie.length);
  201. if ( document.cookie.substring( x, y ) == nameOfCookie ) {
  202. if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
  203. endOfCookie = document.cookie.length;
  204. return unescape( document.cookie.substring( y, endOfCookie ) );
  205. }
  206. x = document.cookie.indexOf( " ", x ) + 1;
  207. if ( x == 0 ) break;
  208. }
  209. return "";
  210. }
  211. /*****************************************************************
  212. **** 设置cookie内容、过期时间 *****
  213. *****************************************************************/
  214. function setCookie( name, value, expiredays ) {
  215. var todayDate = new Date();
  216. todayDate.setDate( todayDate.getDate() + expiredays );
  217. document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
  218. }
  219. /*****************************************************************
  220. **** 检查输入字符 (lhm) *****
  221. '// islegality:输入的字符是否为给定的字符
  222. '//返回值:bool
  223. *****************************************************************/
  224. function islegality(checkstrpass){
  225. var checkokpass="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  226. for (i=0; i<checkstrpass.length; i++) {
  227. ch=checkstrpass.charAt(i);
  228. for (j=0;j<checkokpass.length; j++){
  229. if (ch==checkokpass.charAt(j))
  230. break;
  231. }
  232. if (j==checkokpass.length){
  233. return false; //函有特别字符时返回false
  234. break;
  235. }
  236. }
  237. return true;
  238. }
  239. /**
  240. * 检查输入是否中文
  241. */
  242. function ck_chinese(value_) {
  243. return escape(value_).indexOf("%u")!=-1
  244. }