For the following usage, you need to add the attribute onclick in JSP. For example, onclick = "javascript: allselect ()" // javascript can be omitted.
Or use document. getElementById ("allselectbox"). onclick = function ();
Select All:
Fuction allselect (){
Var form = document. forms [0];
Var state = form. allselectbox. checked;
Var length = form. username. length;
If (length ){
For (var I = 0; I <length; I ++ ){
Form. usernames [I]. checked = state;
}
} Else form. username. check = state;
}
Another method of selecting all:
Function allSelect (){
Var items = document. getElementsByName ("usernames ");
Var state = document. getElementsByName ("allselectbox") [0]. checked;
If (items. length ){
For (var I = 0; I <items. length; I ++ ){
Items [I]. checked = state;
}
} Else {
Items. checked = state;
}
}
Single choice:
Fuction selectitem (){
Var form = document. forms [0];
Var length = form. username. length;
If (length ){
For (var I = 0; I <length; I ++ ){
If (form. usernames [I]. checked) return true;
}
} Else return form. usernames. check;
}
Go to other pages:
Function topage (page ){
Var form = document. forms [0]
Form. page. value = page;
Form. submit;
}
Radio:
Function getradiovalue (objradio ){
Var result = "";
Try {
If (typeof (objradio. value) = "undefined "){
For (var I = 0; I <objradio. length; I ++ ){
If (objradio [I]. checked ){
Return objradio [I]. value;
}
}
} Else {
If (objradio. checked) result = objradio. value;
}
} Catch (e) {result = "";}
Return result;
}
Email Verification:
Function isValidEmail (inEmail ){
Var filter =/^ ([a-zA-Z0-9 _\. \-]) + \ @ ([a-zA-Z0-9 \-]) + \.) + ([a-zA-Z0-9] {2, 4}) + $ /;
Return filter. test (inEmail );
}
Verify the mobile phone format:
Function validateMobile (){
Var form = document. forms [0];
If (form. mobile. value! = ""){
Var num =/^ 1 [35] \ d {9} $/
If (! Num. test (form. mobile. value )){
Alert ("the recipient's mobile phone number format is incorrect ");
Return false;
}
Alert ("correct ");
}
}
To be continued ........
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.