1, <div Id=div1><button Onclick=alert (div1.outerhtml) >outerHTML</button>
<button Onclick=alert (div1.innerhtml) >innerHTML</button>
<button Onclick=alert (Div1.innertext) >innertText</button>
2. Javascript Error
Copy Code code as follows:
w1=0;
W1+=math.round (1333333.99*100);
W1+=math.round (13663.38*100);
document.write (w1/100);
w1=0;
w1+=1333333.99;
w1+=13663.38;
document.write (W1);
3. Form Check
Copy Code code as follows:
Wanghui in 20031020 adds a function checkport () that verifies business access and addresses the address port number.
function Tochndigit (num)
{
var t = parseint (num);
if (t==0) return "0";
if (t==1) return "one";
if (t==2) return "two";
if (t==3) return "three";
if (t==4) return "four";
if (t==5) return "five";
if (t==6) return "six";
if (t==7) return "seven";
if (t==8) return "eight";
if (t==9) return "nine";
Return "";
}
@CheckItem @ opt-hutie-20031208 Optimization: Add a common function that masks all buttons
function Disableallbuttons () {
For (Var i=0;i<document.all.tags ("Input"). length;i++) {
var tmp = document.all.tags ("input") [I];
if (tmp.type== "button" | | | tmp.type== "Submit" | | tmp.type== "Reset") {
Tmp.disabled = true;
}
}
}
Add Trim function
String.prototype.trim = function ()
{
Return This.replace (/(^\s*) | ( \s*$)/g, "");
}
Function Name: Checknum
Feature Description: Check for numbers
Parameter description: The number to check
Return value: 1 is a number, 0 is not a number
function Checknum (Num) {
var i,j,strtemp;
strtemp = "0123456789.";
if (num.length = 0)
return 0
for (i = 0;i < Num.length; i++) {
j = Strtemp.indexof (Num.charat (i));
if (j = = 1) {
Indicates that a character is not a number
return 0;
}
}
Description is a number
return 1;
}
Function Name: Checknum
Feature Description: Check for numbers
Parameter description: The number to check
Return value: 1 is a number, 0 is not a number
function Checkintnum (Num) {
var i,j,strtemp;
strtemp = "0123456789";
if (num.length = 0)
return 0
for (i = 0;i < Num.length; i++) {
j = Strtemp.indexof (Num.charat (i));
if (j = = 1) {
Indicates that a character is not a number
return 0;
}
}
Description is a number
return 1;
}
Function Name: Checkemail
Function Introduction: Check whether for email address
Parameter description: The string to check
Return value: 0: not 1: Yes
function Checkemail (a) {
@CheckItem @ bug141-hutie-20030821 Modify Interface: Email address to do prohibit Chinese check
var reg =/[^\u0000-\u00ff]/;
if (A.match (reg)!=null) {
Return 0;//have Chinese characters
}
var i=a.length;
var temp = a.indexof (' @ ');
var tempd = A.indexof ('. ');
if (Temp > 1) {
if ((i-temp) > 3) {
if ((I-TEMPD) >0) {
return 1;
}
}
}
return 0;
}
Function Name: Checktel
Function Description: Check whether the phone number
Parameter description: The string to check
Return value: 1 is legal, 0 is illegal
function Checktel (tel)
{
var i,j,strtemp;
strtemp = "0123456789-()";
for (i=0;i<tel.length;i++)
{
j = Strtemp.indexof (Tel.charat (i));
if (j==-1)
{
Indicates that there are characters that are not legal
return 0;
}
}
Description Legal
return 1;
}
Function Name: checklength
Feature Description: Check the length of the string
Parameter description: The string to check
Return value: Length value
function Checklength (strtemp)
{
var i,sum;
sum = 0;
for (i=0;i<strtemp.length;i++)
{
@CheckItem @ bug-renhj-20040604 Optimization: Change the validated function to 128 to be a single character of the class. Avoid "·" Symbol
if ((Strtemp.charcodeat (i) >=0) && (Strtemp.charcodeat (i) <=255))
if ((Strtemp.charcodeat (i) >=0) && (Strtemp.charcodeat (i) <=128))
sum = sum + 1;
Else
sum = sum + 2;
}
return sum;
}
Function Name: Checksafe
Function Introduction: Check whether contains "'", "" "," < "," > ","; ",", "
Parameter description: The string to check
Return value: 0: is 1: not
function Checksafe (a)
{
FIBDN = new Array ("'", ' "", ">", "<", ",", ";");
i = fibdn.length;
j = a.length;
for (ii=0;ii<i;ii++)
{
for (jj=0;jj<j;jj++)
{
Temp1 = A.charat (JJ);
Temp2 = Fibdn[ii];
if (TEMP1==TEMP2)
{
return 0;
}
}
}
return 1;
}
Function Name: Checkchar
Feature Description: Check to see if non-alphabetic characters are included
Parameter description: The string to check
Return value: 0: Contains 1: all letters
function Checkchar (str)
{
var strsource = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz." () & ";
var ch;
var i;
var temp;
For (i=0;i<= (str.length-1); i++)
{
ch = str.charat (i);
temp = strsource.indexof (CH);
if (temp==-1)
{
return 0;
}
}
return 1;
}
Function Name: checkcharordigital
Function Introduction: Check whether contains not the numeral or the letter
Parameter description: The string to check
Return value: 0: Contains 1: all digits or letters
function Checkcharordigital (str)
{
var strsource = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ". () & ";
var ch;
var i;
var temp;
for (i = 0;i<= (str.length-1); i++)
{
ch = str.charat (i);
temp = strsource.indexof (CH);
if (temp = = 1)
{
return 0;
}
}
return 1;
}
Function Name: Checkchinese
Function Introduction: Check whether contain Chinese characters
Parameter description: The string to check
Return value: 0: Contains 1: No
function Checkchinese (strtemp)
{
var i,sum;
for (i=0;i<strtemp.length;i++)
{
if ((Strtemp.charcodeat (i) <0) | | (Strtemp.charcodeat (i) >255))
return 0;
}
return 1;
}
Function name: Comparetime ()
Feature Description: Compare time size
Parameter description: Beginyear start year, beginmonth start month, benginday start day, Beginh start hour, beginm start minute,
Endyear end year, Endmonth end month, Endmonth end day, Endh end hour, Endm end minute
Return value: True indicates that the start time is greater than the end time, false instead
function Comparetime (BEGINYEAR,BEGINMONTH,BENGINDAY,BEGINH,BEGINM,ENDYEAR,ENDMONTH,ENDDAY,ENDH,ENDM) {
var date1 = new Date (BEGINYEAR,BEGINMONTH-1,BENGINDAY,BEGINH,BEGINM);
var date2 = new Date (ENDYEAR,ENDMONTH-1,ENDDAY,ENDH,ENDM);
if (Date1.gettime () >date2.gettime ()) {
return false;
}
return true;
}
Function name: Comparedate ()
Feature Description: compare date size
Parameter description: Beginyear start year, beginmonth start month, Benginday start day
Endyear end year, Endmonth end month, Endmonth end Day
Return value: 0:true indicates that the start time is greater than the end time and false instead
function Comparedate (beginyear,beginmonth,benginday,endyear,endmonth,endday) {
var date1 = new Date (beginyear,beginmonth-1,benginday);
var date2 = new Date (endyear,endmonth-1,endday);
if (Date1.gettime () >date2.gettime ()) {
return false;
}
return true;
}
Function Name: Checkurl
Function Description: Check the URL is legitimate
Parameter description: The string to check
Return value: true: Legal false: illegal.
function Checkurl (strtemp)
{
if (strtemp.length==0) return false;
if (Checkchinese (strtemp) ==0) return false;
if (Strtemp.touppercase (). IndexOf ("http://")!= 0 && strtemp.touppercase (). IndexOf ("https://")!= 0) {
return false;
}
return true;
}
@CheckItem @ opt-renhj-20030704 provides a common way to place spaces
Clear left Space
function Js_ltrim (DESTSTR)
{
if (deststr==null) return "";
var pos=0;
var retstr=new String (DESTSTR);
if (retstr.lenght==0) return retstr;
while (retstr.substring (pos,pos+1) = = "") pos++;
Retstr=retstr.substring (POS);
return (RETSTR);
}
Clear right space
function Js_rtrim (DESTSTR)
{
if (deststr==null) return "";
var retstr=new String (DESTSTR);
var pos=retstr.length;
if (pos==0) return retstr;
while (POS && retstr.substring (pos-1,pos) = "") pos--;
Retstr=retstr.substring (0,pos);
return (RETSTR);
}
Clear left and right spaces
function Js_trim (DESTSTR)
{
if (deststr==null) return "";
var retstr=new String (DESTSTR);
var pos=retstr.length;
if (pos==0) return retstr;
Retstr=js_ltrim (RETSTR);
Retstr=js_rtrim (RETSTR);
return retstr;
}
Format the date string entered, such as: "2003-9-12" output: "2003-09-12"
function Formatdatestr (indate) {
if (indate==null| | indate== "") return "";
var begindate = Indate.split ("-");
var myear=begindate[0];
var mmonth=begindate[1];
var mday=begindate[2];
Mmonth= (mmonth.length==1)? (" 0 "+mmonth): Mmonth);
Mday= (mday.length==1)? (" 0 "+mday): Mday);
return myear+ "-" +mmonth+ "-" +mday;
}
Added by Wanghui 20031020 the legality of the port checking the URL address must be a number less than 65535
function Checkport (invalue1,invalue2) {
First check the legality of the first parameter, if the second parameter is NULL, then the first parameter represents the ' business address ' of the SMS business
if (inValue1!= null && invalue1.value!= "") {
var array1 = InValue1.value.split (":");
if (Array1.length >=4) {//If the length of the array in ': ' is four, then there are two ': ', so it is illegal.
if (invalue2==null) alert ("Business processing address port format error");
ELSE alert ("Business access address port format error");
Invalue1.focus ();
return false;
}
if (array1.length >= 3) {
Port1 = array1[2];
if (pos1 = Port1.indexof ("/")) >= 0) {//view the port after the '/', if yes, the symbol before the port
Port1 = port1.substring (0,POS1)
}
if (Port1 = = "" | | Checkintnum (port1) = = 0 | | port1>65535) {
if (inValue2 = null) alert ("The Business processing address port must be a number and cannot be greater than 65535");
Else alert ("The Business access address port must be a number and cannot be greater than 65535");
Invalue1.focus ();
return false;
}
}
}
Check the legality of the second argument again.
if (inValue2!= null && invalue2.value!= "") {
var array2 = InValue2.value.split (":");
if (Array2.length >=4) {
Alert ("Business processing address port format error");
Invalue2.focus ();
return false;
}
if (array2.length >= 3) {
Port2 = array2[2];
if ((Pos2 = Port2.indexof ("/")) >= 0) {
Port2 = port2.substring (0,POS2)
}
if (Port2 = = "" | | Checkintnum (port2) = = 0 | | port2>65535) {
Alert ("The Business processing address port must be a number and cannot be greater than 65535");
Invalue2.focus ();
return false;
}
}
}
return true;
}
OBJ: Data Objects
DISPSTR: Failure prompt Content Display string
function Checkurlvalid (obj, dispstr)
{
if (obj = null)
{
Alert ("Incoming object is null");
return false;
}
var str = obj.value;
var urlpatern0 =/^https?:\ /\/.+$/i;
if (!urlpatern0.test (str))
{
Alert (dispstr+ "illegal: Must start with ' http:\/\/' or ' https:\/\/')";
Obj.focus ();
return false;
}
var urlpatern2=/^https?:\ /\/([a-za-z0-9_-]) + (\.)?) * (: \d+)? +$/i;
if (!urlpatern2.test (str))
{
Alert (dispstr+ "port number must be a number and should be between 1-65535!");
Obj.focus ();
return false;
}
var urlpatern1 =/^https?:\ /\/([a-za-z0-9_-]) + (\.)?) * (: \d+)? (\/((\.)? (\?)? =?&? [a-za-z0-9_-] (\?)?) *) *$/i;
if (!urlpatern1.test (str))
{
Alert (dispstr+ "illegal, please check!");
Obj.focus ();
return false;
}
var s = "0";
var t = 0;
var re = new RegExp (": \\d+", "IG");
while ((arr = re.exec (str))!=null)
{
s = str.substring (Regexp.index+1,regexp.lastindex);
if (s.substring (0,1) = = "0")
{
Alert (dispstr+ "port number cannot begin with 0!");
Obj.focus ();
return false;
}
T = parseint (s);
if (t<1 | | t >65535)
{
Alert (dispstr+ "port number must be a number and should be between 1-65535!");
Obj.focus ();
return false;
}
}
return true;
}
Function Name: CHECKVISIBLEENGLISHCHR
Function Description: Check whether the English character can be displayed (!) #$%& ' () *+,-./0123456789:;<=> @ABCDEFGHIJKLMNOPQRSTUVWXYZ [\]^_ ' abcdefghijklmnopqrstuvwxyz{|} ~)
Parameter description: The string to check
return value: True|false
Add by Renhj 2004.01.05
function CHECKVISIBLEENGLISHCHR (strtemp)
{
var i;
for (i=0;i<strtemp.length;i++)
{
if ((Strtemp.charcodeat (i) <32) | | (Strtemp.charcodeat (i) >126))
return false;
}
return true;
}
Function Name: CHECKINPUTCHR
Feature Description: Check for non-input characters
Parameter description: The string to check
Return value: False: Contains true: All are available as input characters
Add by Renhj 2004.01.05
function CHECKINPUTCHR (str)
{
var notinput = "<>";
var i;
for (i = 0; Notinput!= null && i < notinput.length; i++) {
if (Str.indexof (Notinput.charat (i)) >= 0) {//if any
return false;
}
}
return true;
}
Function Name: Checktelext
Feature Description: Check for phone number, and no extension number
Parameter description: The string to check
Return value: 1 is legal, 0 is illegal
function Checktelext (tel)
{
var I,count,isnumber;
Count = 0; There are several consecutive numbers of strings
Isnumber = 0; Not numbers.
for (i=0;i<tel.length;i++)
{
Determine whether the current number
if (Checkintnum (Tel.charat (i)) = = 1)
{
if (isnumber = 0)
{
Count = count + 1;
}
Isnumber = 1;
}else{
Isnumber = 0;
}
if (Count > 2)
{
Indicates a character is illegal or has an extension number
return 0;
}
}
if ((Checkintnum (Tel.charat (0)) = = 1) &&
(Checkintnum (Tel.charat (tel.length-1)) = = 1)) {
Description Legal
return 1;
}else{
Indicates that there are characters that are not legal
return 0;
}
}
Function Name: Checkformdata
Feature Description: Check the Form object
Parameter description:
OBJ: The object to check,
Name: The Chinese names of the objects to check,
Length: Check the lengths of the objects (<0 not checked),
Notnull: True to check for Non-null,
Notspecchar: True to check for any special characters,
Notchinesschar: True to check for any Chinese characters,
Numorletter: True to check only for numbers or English letters,
Pnumber: True to check for positive integers only,
Return value: false: Check does not pass true: all are available as input characters
Add by Renhj 2004.03.19
@CheckItem @ bug:1641:718-renhj-20040902-add5 Modify the information of the checksum number
function Checkformdata (obj,name,length,notnull,notspecchar,notchinesschar,numorletter,pnumber) {
Check Object
if (!obj) {alert ("The target is not an object, processing failed!"); return false;}
var msg;
var Ilen;
Detecting Chinese characters
if (notchinesschar&& (Checkchinese (obj.value)!= 1)) {
Msg=name+ "cannot contain Chinese characters!" ";
Alert (msg);
Obj.focus ();
return false;
}
Detecting special characters
if (notspecchar&& (!CHECKINPUTCHR (obj.value)) {
var notinput = "<>";
Msg=name+ "has illegal characters (" +notinput+ ")! ";
Alert (msg);
Obj.focus ();
return false;
}
Detection length
if (length>=0&& (Checklength (obj.value) >length)) {
ILEN=LENGTH/2;
if (Pnumber) {
Msg=name+ "Can not exceed the" +length+ "number! ";
}else if (Notchinesschar) {
Msg=name+ "not more than" +length+ "English! ";
}else{
Msg=name+ "Can not surpass" +length+ "an English or" +ilen+ "a Chinese character! ";
}
Alert (msg);
Obj.focus ();
return false;
}
Detect non-null
if (notnull&&obj.value== "") {
msg= "Please input" +name+ "! ";
Alert (msg);
Obj.focus ();
return false;
}
Test can only be numeric or English letters
re =/[\w_]/;
if (Numorletter&&re.exec (Obj.value)) {
Msg=name+ "Only for numbers or English letters!" ";
Alert (msg);
Obj.focus ();
return false;
}
Detection can only be a positive integer
re =/[\d_]/;
if (Pnumber&&re.exec (Obj.value)) {
Msg=name+ "can only be a positive integer!" ";
Alert (msg);
Obj.focus ();
return false;
}
return true;
}