javascript 一些用法小结_javascript技巧
程序员文章站
2024-04-04 09:54:41
...
如下的用法需要在JSP中增加属性onclick. 以全选为例,onclick="javascript:allselect()"//javascript可以省略
或者将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;iform.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[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;iif(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;iif(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("正确");
}
}
待续........
或者将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
}
}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[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
}
}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
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("正确");
}
}
待续........
推荐阅读
-
c#和Javascript操作同一json对象的实现代码_javascript技巧
-
setTimeout在类中使用的问题!_javascript技巧
-
纯js实现的论坛常用的运行代码的效果_javascript技巧
-
Javascript实现滑块滑动改变值的实现代码_javascript技巧
-
javascript使用eval或者new Function进行语法检查_javascript技巧
-
IE与Firefox在JavaScript上的7个不同写法小结_javascript技巧
-
iframe 自适应高度[在IE6 IE7 FF下测试通过]_javascript技巧
-
Javascript 去除数组的重复元素_javascript技巧
-
javascript 获取所有id中包含某关键字的控件的实现代码_javascript技巧
-
Javascript 函数对象的多重身份_javascript技巧