Home  >  Article  >  Web Front-end  >  Summary of some usage of javascript_javascript skills

Summary of some usage of javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:46:46962browse

The following usage requires adding the attribute onclick in JSP. Taking all selection as an example, onclick="javascript:allselect()"//javascript can omit
or use document.getElementById("allselectbox") for function allselect(). 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;iform.usernames[i].checked=state;
}
}else form.username.check = state;
} Another way of writing
select all:
function allSelect(){
var items = document.getElementsByName("usernames") ;
var state = document.getElementsByName("allselectbox")[0].checked;
if(items.length){
for(var i = 0; i items[i].checked = state;
}
}else{
items.checked = state;
}
}
Single selection:
fuction selectitem (){
var form = document.forms[0];
var length = form.username.length;
if(length){
for(var i=0;iif(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;
}
Get the value of the radio button Radio:
function getradiovalue(objradio){
var result = "";
try{
if(typeof(objradio.value)=="undefined"){
for(var i =0;iif(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);
}
Check 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 format of the consignee's mobile phone number is incorrect");
return false;
}
alert("correct");
}
}
To be continued.....

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn