29:如何控制横向和纵向滚动条的显隐?
<body style="overflow-y:hidden"> 去掉x轴
<body style="overflow-x:hidden"> 去掉y轴
<body scroll="no">不显
/////////////////////////////////////////////////////////////////////
30:javascript中获取地址栏参数比如 index.jsp?id=xxx&name=xxx
方法一:
<script>
function getvalue(name)
{
var str=window.location.search;
if (str.indexOf(name)!=-1)
{
var pos_start=str.indexOf(name)+name.length+1;
var pos_end=str.indexOf("&",pos_start);
if (pos_end==-1)
{
return str.substring(pos_start);
}
else
{
return str.substring(pos_start,pos_end)
}
}
else
{
return "没有这个name值";
}
}
var strName=prompt("请输入您所要值的名字");
alert(getvalue(strName));
</script>
方法二:
<script language="javascript">
var URLParams = new Array();
var aParams = document.location.search.substr(1).split('&');
for (i=0;i<aParams.length;i++){
var aParam = aParams.split("=");
URLParams[aParam[0]] = aParam[1];
}
//取得传过来的name参数
var v=URLParams["name"];
alert("name==="+v);
</script>
方法三:
<script type="text/javascript">
Request = {
QueryString : function(item){
var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
return svalue ? svalue[1] : svalue;
}
}
alert(Request.QueryString("name"));
</script>
////////////////////////////////////////////////////////////////////
31:window对象的方法
open(URL,WindowName,parameterList)pen方法创建一个新的浏览器窗口,并在新窗口中载入一个指定的URL地址。
close():close方法关闭一个浏览器窗口.
alert(text):弹出一个信息框.
confirm(text):弹出一个确认框.
prompt(text,Defaulttext):弹出一个提示框.
setTimeout(expression,time):定时设置,在一定时间后自动执行expression描述的代码,使用time设置时间,单位是毫秒.
clearTimeout(timer):取消以前的定时设置.
back():指示浏览器载入历史记录中的上一个URL地址.
forward():指示浏览器载入历史记录中的下一个URL地址.
stop():指示浏览器停止网页的装载.
location:提供当前窗口的URL信息
history:提供当前窗口的历史记录,可以在网页导航中发挥作用.
closed:一个指出窗口目前是否关闭的逻辑值.
self:引用当前文档对应的窗口.
navigate(url):窗口转向另外一个窗口
32:验证是否整数
<script type="text/javascript">
function checkInteger(v){
var s = ""+v;
var ret = s.match(/^(-|\+)?\d+$/);
if(ret==null){
alert(v+" , 不是数字");
}
}
checkInteger('01230');
checkInteger("abc");
</script>
33:验证是否都是数字,而且是正整数
<script type="text/javascript">
function checkGreaterZero(v){
var s = ""+v;
var ret = s.match(/^\d+$/);
if(ret==null){
alert(v+" , 不是数字");
}
}
checkGreaterZero('1230');
checkGreaterZero("abc");
</script>
34:验证是否都是数字,而且是负整数
<script type="text/javascript">
function checkLitterZero(v){
var s = ""+v;
var ret = s.match(/^-\d+$/);
if(ret==null){
alert(v+" , 不是小于0的数字");
}
}
checkLitterZero('-1230');
checkLitterZero("123");
</script>
35:短时间,形如 (13:04:06)
<script language="javascript">
function isTime(str)
{
var a = str.match(/^(\d{1,2})(?(\d{1,2})\2(\d{1,2})$/);
if (a == null) {alert('输入的参数不是时间格式'); return false;}
if (a[1]>24 || a[3]>60 || a[4]>60)
{
alert(str+",时间格式不对");
return false
}
return true;
}
isTime("12:09:39");
isTime("33:55:99");
</script>
36:短日期,形如 (2008-12-05)
<script language="javascript">
function strDateTime(str)
{
var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r==null)return false;
var d= new Date(r[1], r[3]-1, r[4]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}
alert(strDateTime("2008-10-28"));
alert(strDateTime("08-12-9"));
</script>
37:长时间,形如 (2003-12-05 13:04:06)
<script language="javascript">
function strDateTime(str)
{
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2})\d{1,2})\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}
alert(strDateTime("2008-10-28 11:11:11"));
alert(strDateTime("08-12-9 11:11:11"));
</script>
38:检测值不能为空
<script language="javascript">
function canNotEmpty(str)
{
if(str.replace(/^\s+|\s+$/g,'')==''){
alert('不能为空!');
}
return true;
}
alert(canNotEmpty("2008-10-28 11:11:11"));
alert(canNotEmpty(" "));
</script>
39:判断字符全部由a-Z或者是A-Z的字字母组成
<script language="javascript">
function isLetter(str)
{
if(/[^a-zA-Z]/g.test(str)){
return false;
}
return true;
}
alert(isLetter("aaaSSFsadfa"));
alert(isLetter("a3d"));
</script>
40:判断字符由字母和数字组成
<script language="javascript">
function isLetter(str)
{
if(/[^0-9a-zA-Z]/g.test(this.value)){
return false;
}
return true;
}
alert(isLetter("aaaSSFsadfa"));
alert(isLetter("a3d"));
</script>
41:判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母
<script language="javascript">
function isLetter(str)
{
if(/^([a-zA-z_]{1})([\w]*)$/g.test(str)){
return true;
}
return false;
}
alert(isLetter(" aaaSSFsadfa"));
alert(isLetter("_a3d"));
</script>
42:判断浏览器的类型
<script language="javascript">
alert(window.navigator.appName);
</script>
43:判断ie的版本
<script language="javascript">
alert(window.navigator.appVersion);
</script>
44:判断客户端的分辨率
<script language="javascript">
alert(window.screen.height);
alert(window.screen.width);
</script>
45:用正则表达式判断是否Email
<script language="javascript">
function isMail(mail)
{
return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
}
alert(isMail("cc@a.com"));
alert(isMail("cc 1@a.com"));
</script>
46:用正则表达式判断是否身份证号码
<script language="javascript">
function isIdCardNo(num)
{
if (isNaN(num)) {alert("输入的不是数字!"); return false;}
var len = num.length, re;
if (len == 15)
re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
else if (len == 18)
re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d)$/);
else {alert("输入的数字位数不对!"); return false;}
var a = num.match(re);
if (a != null)
{
if (len==15)
{
var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
else
{
var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
if (!B) {alert("输入的身份证号 "+ a[0] +" 里出生日期不对!"); return false;}
}
return true;
}
alert(isIdCardNo("511111199001013456"));
alert(isIdCardNo("511111199013313456"));
</script>
47:给表格自动增行(msdn的例子)
<SCRIPT>
function createRows(){
// insert two rows.
var oRow1=oTable.insertRow(oTable.rows.length);
var oRow2=oTable.insertRow(oTable.rows.length);
// retrieve the rows collection for the table.
var aRows=oTable.rows;
// retrieve the cells collection for the first row.
var aCells=oRow1.cells;
// insert two cells into the first row.
var oCell1_1=aRows(oRow1.rowIndex).insertCell(aCells.length);
var oCell1_2=aRows(oRow1.rowIndex).insertCell(aCells.length);
// retrieve the cells collection for the second row.
aCells=oRow2.cells;
// insert two cells into the second row.
var oCell2_1=aRows(oRow2.rowIndex).insertCell(aCells.length);
var oCell2_2=aRows(oRow2.rowIndex).insertCell(aCells.length);
// Add regular HTML values to the 4 new cells.
oCell1_1.innerHTML="<B>Cell 1.1!</B>";
oCell1_2.innerHTML="<B>Cell 1.2!</B>";
oCell2_1.innerHTML="<B>Cell 2.1!</B>";
oCell2_2.innerHTML="<B>Cell 2.2!</B>";
}
</SCRIPT>
<INPUT TYPE="button" VALUE="Create Rows">
<TABLE BORDER=1 ID="oTable">
</TABLE>
48:严格的身份证验证
<script>
var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"xizang",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}
function cidInfo(sId){
var iSum=0
var info=""
if(!/^\d{17}(\d|x)$/i.test(sId))return false;
sId=sId.replace(/x$/i,"a");
if(aCity[parseInt(sId.substr(0,2))]==null)return "Error:非法地区";
sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
var d=new Date(sBirthday.replace(/-/g,"/"))
if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "Error:非法生日";
for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11)
if(iSum%11!=1)return "Error:非法证号";
return aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女")
}
document.write(cidInfo("380524198002300016"),"<br/>");
document.write(cidInfo("340524198002300019"),"<br/>")
document.write(cidInfo("340524197711111111"),"<br/>")
document.write(cidInfo("34052419800101001x"),"<br/>");
</script>
49:验证IP地址
<SCRIPT LANGUAGE="JavaScript">
function isip(s){
var check=function(v){try{return (v<=255 && v>=0)}catch(x){return false}};
var re=s.split(".")
return (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false
}
var s="202.197.78.129";
alert(isip(s))
</SCRIPT>
29:如何控制横向和纵向滚动条的显隐?
<body style="overflow-y:hidden"> 去掉x轴
<body style="overflow-x:hidden"> 去掉y轴
<body scroll="no">不显
/////////////////////////////////////////////////////////////////////
30:javascript中获取地址栏参数比如 index.jsp?id=xxx&name=xxx
方法一:
<script>
function getvalue(name)
{
var str=window.location.search;
if (str.indexOf(name)!=-1)
{
var pos_start=str.indexOf(name)+name.length+1;
var pos_end=str.indexOf("&",pos_start);
if (pos_end==-1)
{
return str.substring(pos_start);
}
else
{
return str.substring(pos_start,pos_end)
}
}
else
{
return "没有这个name值";
}
}
var strName=prompt("请输入您所要值的名字");
alert(getvalue(strName));
</script>
方法二:
<script language="javascript">
var URLParams = new Array();
var aParams = document.location.search.substr(1).split('&');
for (i=0;i<aParams.length;i++){
var aParam = aParams.split("=");
URLParams[aParam[0]] = aParam[1];
}
//取得传过来的name参数
var v=URLParams["name"];
alert("name==="+v);
</script>
方法三:
<script type="text/javascript">
Request = {
QueryString : function(item){
var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
return svalue ? svalue[1] : svalue;
}
}
alert(Request.QueryString("name"));
</script>
////////////////////////////////////////////////////////////////////
31:window对象的方法
open(URL,WindowName,parameterList)pen方法创建一个新的浏览器窗口,并在新窗口中载入一个指定的URL地址。
close():close方法关闭一个浏览器窗口.
alert(text):弹出一个信息框.
confirm(text):弹出一个确认框.
prompt(text,Defaulttext):弹出一个提示框.
setTimeout(expression,time):定时设置,在一定时间后自动执行expression描述的代码,使用time设置时间,单位是毫秒.
clearTimeout(timer):取消以前的定时设置.
back():指示浏览器载入历史记录中的上一个URL地址.
forward():指示浏览器载入历史记录中的下一个URL地址.
stop():指示浏览器停止网页的装载.
location:提供当前窗口的URL信息
history:提供当前窗口的历史记录,可以在网页导航中发挥作用.
closed:一个指出窗口目前是否关闭的逻辑值.
self:引用当前文档对应的窗口.
navigate(url):窗口转向另外一个窗口
32:验证是否整数
<script type="text/javascript">
function checkInteger(v){
var s = ""+v;
var ret = s.match(/^(-|\+)?\d+$/);
if(ret==null){
alert(v+" , 不是数字");
}
}
checkInteger('01230');
checkInteger("abc");
</script>
33:验证是否都是数字,而且是正整数
<script type="text/javascript">
function checkGreaterZero(v){
var s = ""+v;
var ret = s.match(/^\d+$/);
if(ret==null){
alert(v+" , 不是数字");
}
}
checkGreaterZero('1230');
checkGreaterZero("abc");
</script>
34:验证是否都是数字,而且是负整数
<script type="text/javascript">
function checkLitterZero(v){
var s = ""+v;
var ret = s.match(/^-\d+$/);
if(ret==null){
alert(v+" , 不是小于0的数字");
}
}
checkLitterZero('-1230');
checkLitterZero("123");
</script>
35:短时间,形如 (13:04:06)
<script language="javascript">
function isTime(str)
{
var a = str.match(/^(\d{1,2})(?(\d{1,2})\2(\d{1,2})$/);
if (a == null) {alert('输入的参数不是时间格式'); return false;}
if (a[1]>24 || a[3]>60 || a[4]>60)
{
alert(str+",时间格式不对");
return false
}
return true;
}
isTime("12:09:39");
isTime("33:55:99");
</script>
36:短日期,形如 (2008-12-05)
<script language="javascript">
function strDateTime(str)
{
var r = str.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
if(r==null)return false;
var d= new Date(r[1], r[3]-1, r[4]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}
alert(strDateTime("2008-10-28"));
alert(strDateTime("08-12-9"));
</script>
37:长时间,形如 (2003-12-05 13:04:06)
<script language="javascript">
function strDateTime(str)
{
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2})\d{1,2})\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}
alert(strDateTime("2008-10-28 11:11:11"));
alert(strDateTime("08-12-9 11:11:11"));
</script>
38:检测值不能为空
<script language="javascript">
function canNotEmpty(str)
{
if(str.replace(/^\s+|\s+$/g,'')==''){
alert('不能为空!');
}
return true;
}
alert(canNotEmpty("2008-10-28 11:11:11"));
alert(canNotEmpty(" "));
</script>
39:判断字符全部由a-Z或者是A-Z的字字母组成
<script language="javascript">
function isLetter(str)
{
if(/[^a-zA-Z]/g.test(str)){
return false;
}
return true;
}
alert(isLetter("aaaSSFsadfa"));
alert(isLetter("a3d"));
</script>
40:判断字符由字母和数字组成
<script language="javascript">
function isLetter(str)
{
if(/[^0-9a-zA-Z]/g.test(this.value)){
return false;
}
return true;
}
alert(isLetter("aaaSSFsadfa"));
alert(isLetter("a3d"));
</script>
41:判断字符由字母和数字,下划线,点号组成.且开头的只能是下划线和字母
<script language="javascript">
function isLetter(str)
{
if(/^([a-zA-z_]{1})([\w]*)$/g.test(str)){
return true;
}
return false;
}
alert(isLetter(" aaaSSFsadfa"));
alert(isLetter("_a3d"));
</script>
42:判断浏览器的类型
<script language="javascript">
alert(window.navigator.appName);
</script>
43:判断ie的版本
<script language="javascript">
alert(window.navigator.appVersion);
</script>
44:判断客户端的分辨率
<script language="javascript">
alert(window.screen.height);
alert(window.screen.width);
</script>
45:用正则表达式判断是否Email
<script language="javascript">
function isMail(mail)
{
return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
}
alert(isMail("cc@a.com"));
alert(isMail("cc 1@a.com"));
</script>
46:用正则表达式判断是否身份证号码
<script language="javascript">
function isIdCardNo(num)
{
if (isNaN(num)) {alert("输入的不是数字!"); return false;}
var len = num.length, re;
if (len == 15)
re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
else if (len == 18)
re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\d)$/);
else {alert("输入的数字位数不对!"); return false;}
var a = num.match(re);
if (a != null)
{
if (len==15)
{
var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
else
{
var D = new Date(a[3]+"/"+a[4]+"/"+a[5]);
var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5];
}
if (!B) {alert("输入的身份证号 "+ a[0] +" 里出生日期不对!"); return false;}
}
return true;
}
alert(isIdCardNo("511111199001013456"));
alert(isIdCardNo("511111199013313456"));
</script>
47:给表格自动增行(msdn的例子)
<SCRIPT>
function createRows(){
// insert two rows.
var oRow1=oTable.insertRow(oTable.rows.length);
var oRow2=oTable.insertRow(oTable.rows.length);
// retrieve the rows collection for the table.
var aRows=oTable.rows;
// retrieve the cells collection for the first row.
var aCells=oRow1.cells;
// insert two cells into the first row.
var oCell1_1=aRows(oRow1.rowIndex).insertCell(aCells.length);
var oCell1_2=aRows(oRow1.rowIndex).insertCell(aCells.length);
// retrieve the cells collection for the second row.
aCells=oRow2.cells;
// insert two cells into the second row.
var oCell2_1=aRows(oRow2.rowIndex).insertCell(aCells.length);
var oCell2_2=aRows(oRow2.rowIndex).insertCell(aCells.length);
// Add regular HTML values to the 4 new cells.
oCell1_1.innerHTML="<B>Cell 1.1!</B>";
oCell1_2.innerHTML="<B>Cell 1.2!</B>";
oCell2_1.innerHTML="<B>Cell 2.1!</B>";
oCell2_2.innerHTML="<B>Cell 2.2!</B>";
}
</SCRIPT>
<INPUT TYPE="button" VALUE="Create Rows">
<TABLE BORDER=1 ID="oTable">
</TABLE>
48:严格的身份证验证
<script>
var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"xizang",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"}
function cidInfo(sId){
var iSum=0
var info=""
if(!/^\d{17}(\d|x)$/i.test(sId))return false;
sId=sId.replace(/x$/i,"a");
if(aCity[parseInt(sId.substr(0,2))]==null)return "Error:非法地区";
sBirthday=sId.substr(6,4)+"-"+Number(sId.substr(10,2))+"-"+Number(sId.substr(12,2));
var d=new Date(sBirthday.replace(/-/g,"/"))
if(sBirthday!=(d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate()))return "Error:非法生日";
for(var i = 17;i>=0;i --) iSum += (Math.pow(2,i) % 11) * parseInt(sId.charAt(17 - i),11)
if(iSum%11!=1)return "Error:非法证号";
return aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女")
}
document.write(cidInfo("380524198002300016"),"<br/>");
document.write(cidInfo("340524198002300019"),"<br/>")
document.write(cidInfo("340524197711111111"),"<br/>")
document.write(cidInfo("34052419800101001x"),"<br/>");
</script>
49:验证IP地址
<SCRIPT LANGUAGE="JavaScript">
function isip(s){
var check=function(v){try{return (v<=255 && v>=0)}catch(x){return false}};
var re=s.split(".")
return (re.length==4)?(check(re[0]) && check(re[1]) && check(re[2]) && check(re[3])):false
}
var s="202.197.78.129";
alert(isip(s))
</SCRIPT>