Commonly used JavaScript functions, collected. . .

xiaoxiao2021-03-06  70

/ * * Return the current month and week * / function holedate () {var D, s = ""; var day = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var D = new date (); s = d.Getyear () "-"; s = (D.GETMONTH () 1) "-"; s = D.Getdate () ""; s = day [d.getday ()] return s;}

/ * * Select or completely cancel checkbox * ename is a full-choice checkbox name * flag is status, true (1 / true) is all selected, false (0 / flase) is a full cancellation * / function selectall (ename, flag) {N = document.getlementsByname (ename); for (i = 0; i

/ * * Check if checkbox has a selected * Parameter ename for checkbox name * Returns: There is a selected object to return True, and return false * / function checkselect (ename) {n = document.getlementsByname (ENAME); for (i = 0; i

/ * * The correctness of the month and day in the date of detection * Date format, 2004-05-04 * / Function Datecheck (VAL) {var mydate = val.split ("-"); var yeear = mydate [0] % 4; // Get whether it is a Run-year VAR MONTH = MyDate [1]; // Get the month VAR day = mydate [2]; // Nuclear day IF (Month> 12 || Month == 0 || day == 0) {RETURN FALSE;} IF (Month == 4 || Month == 6 || Month == 9 || Month == 11) {IF (DAY> 30) Return False; Else Return True;} else {if (year == 0 && day> 29) // Run Moon days RETURSE; Else IF (Year! = 0 && day> 28) Return False; Else Return True;} else {IF (Day> 31) RETURN FALSE; ELSE Return True;}}

/ * * Function: Form content format detection * Parameters OBJ is the form name (ID) * chkType is the type, referred to the function of the function *, for example: Chk ("Document.Ansrname", 3) to test whether it is a username format * / function chk (obj, chktype) {var obj = evAl (obj); switch (chktype) {case 1: // Judgment is empty if (obj.value == ") {Alert (" Please enter the necessary characters "); Obj.focus (); obj.select (); return false;} Break; case 2: // Judgment whether it is digital varreg = /^/d (/./d )?/; IF ( ! reg.test (obj.value)) {Alert ("Please enter the number."); obj.focus (); obj.select (); return false;} Break; case 3: // Judgment is a username format Var reg = / ^ [^ / d / -_] [/ w / -] * [^ / -_] $ /; if (! reg.test (obj.value) {alert ("Please enter the correct format Obj.focus (); obj.select (); return false;} Break; case 4: // Judging whether it is Chinese character var rag = / ^ [/ u4e00- / u9fa5] * $ /; if (! REG.TEST ("" You entered is not all Chinese characters. "); obj.focus (); obj.select (); return false;} Break; case 5: // Judgment is a mailbox Format var REG = / ^ [^ / d / -_] [/ w / -] * [^ / -_] @ [^ / -] [A-ZA-Z / D / -] [^ / -] (/) (/)】】】】 (! reg.test)】 【】 (!) /; if (!regs) (Obj.value)) {Alert ("You enter the correct mailbox format."); Obj.focus (); Obj.select (); return false;} Break; Case 6: // Judging whether it is a legal date format (for example: 2004-01-02) VAR REG = / ^ (19 | 20) / D / D / - (0 | 1) / D / - (0 | 1 | 2 | 3) / D $ /; if (! Reg.test (obj.value)) {Alert ("You entered the correct date format.

"); Obj.focus (); obj.select (); return false;} Break;}}