|
或者將function allselect()用document.getElementById("allselectbox").onclick = function();
全選:
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;
}
全選的另一種寫法:
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;
}
}
單項選擇:
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;
}
轉到其他頁面:
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驗證:
function isValidEmail(inEmail){
var filter = /^([a-zA-Z0-9_/./-])+/@(([a-zA-Z0-9/-])+/.)+([a-zA-Z0-9]{2,4})+$/;
return filter.test(inEmail);
}
檢驗手機格式:
function validateMobile(){
var form = document.forms[0];
if(form.mobile.value!=""){
var num = /^1[35]/d{9}$/
if(!num.test(form.mobile.value)){
alert("收貨人的手機號格式不正確");
return false;
}
alert("正確");
}
}
待續........
JavaScript技術:javascript 一些用法小結,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。