Home > Article > Web Front-end > Summary of some usage of javascript_javascript skills
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;i
}
}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;i
}
}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;i
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.....