数组
var ary=new Array();
ary[0]="yes";
ary[1]="no";
//document.write(ary.toString());
var ary=["red","yellow","blue"];
document.write(ary+"<br/>");
document.write(ary.length);
//用for--in --迭代
for(var index in ary){
document.write(" "+ary[index]+" ");
}
//拼接
document.write(ary.join("-")+"<br/>");
//反转,对其本身作改变
document.write(ary.reverse()+"<br/>");
//排序,按ASII码
ary.sort();
document.write(ary);
--------------------------------------------------------------------
<script>
function mycompare(x,y)
{
var result=0;
var a=parseInt(x);
var b=parseInt(y);
if(a>b)
{
result=1;
}
else if(a<b)
{
result=-1;
}
return result;
}
var ary=new Array();
var ary=["ww","yy","aaa"];
ary[0]="zs";
ary[1]="ls";
document.write(ary+"<br/>");
ary[2]="bbb";
document.write(ary.length);
for(var index in ary)
{
document.write(ary[index]+"<br/>")
}
//数组元素拼接
document.write(ary.join()+"<br/>");
//数组元素转置
ary.reverse();
document.write(ary+"<br/>");
var ary1=[2,20,4,5,12];
document.write(ary1+"<br/>");
//排序
ary1.sort(mycompare);
document.write(ary1+"<br/>");
//数组拼接
var ary2=["a","b","c"];
var ary3=["e","f"];
var ary4=ary2.concat(ary3,ary3);
var ary5=ary4.concat("g","h",ary3);
document.write(ary5+"<br/>")
//返回选定的元素
document.write( ary5.slice(2,80)+"<br/>");
//替换元素
var ary6=["zs","ls","ww"];
document.write(ary6+"<br/>")
ary6.splice(1,1,"adsf","adsf");
document.write(ary6+"<br/>")
document.write(ary6.pop()+"<br/>");
document.write(ary6);
</script>
--------------------------------------------------------------------
锯齿数组
var arys=[["SQL SERVER","C# OOP"],["WEB FORM","HTML/CSS/JAVASCRIPT","ORACLE","ADO.NET"],["ASP.NET","LINQ"]];
document.write(11+"----------------------------<br/>");
for(var index in arys){
document.write(arys[index]+"<br/>");
}
document.write("<hr/>");
for(var index in arys){
for(var i in arys[index]){
document.write("第"+(parseInt(index)+1)+"个子数组里面的元素为:"+arys[index][i]+"<br/>");
}
document.write("<hr/>");
}
--------------------------------------------------------------------
--------------------------------------------------------------------
时间
var now=new Date();
document.write(now.toTimeString()+"<br/>");
document.write(now.toLocaleString()+"<br/>");
document.write(now.toDateString()+"<br/>");
var now = new Date();
var year = now.getYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var day = now.getDay();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var dayStr = "日一二三四五六";
var strDateTime = "今天日期是:" +year + "年" + month + "月" + date + "日 星期" + dayStr.charAt(day) + " 现在时间是:" + hour + "时" + minute + "分" + second + "秒";
document.write(strDateTime+"<br/>");
--------------------------------------------------------------------
<html>
<head>
<title>网站地址管理</title>
<script type="text/javascript">
var stopid;
function timeGo(){
var time=new Date();
document.getElementById("heretime").innerText=time.toLocaleString();
}
function timeStart(){
stopid=window.setInterval("timeGo()",1000);
}
function timeStop(){
window.clearInterval(stopid);
}
</script>
</head>
<body>
<input type="button" value="开始" onClick="timeStart();"/>
<input type="button" value="停止" onClick="timeStop();"/><br/><br/>
<span id="heretime"></span>
</body>
</html>
--------------------------------------------------------------------
<html>
<head>
<title>网站地址管理</title>
<script type="text/javascript">
var stopid;
function timeStart(){
var time=new Date();
document.getElementById("heretime").innerText=time.toLocaleString();
stopid=window.setTimeout("timeStart();",1000);
}
function timeStop(){
window.clearTimeout(stopid);
}
</script>
</head>
<body>
<input type="button" value="开始" οnclick="timeStart();"/>
<input type="button" value="停止" οnclick="timeStop();"/><br/><br/>
<span id="heretime"></span>
</body>
</html>
--------------------------------------------------------------------
函数判断质数
function ck(no){
var flag=true;
for(var i=2;i<no/2;i++){
if(no%i==0){
flag=false;
}
}
return flag;
}
var num=33565;
document.write(ck(num)?"这是一个质数":"这不是质数");
--------------------------------------------------------------------
--------------------------------------------------------------------
创建元素
<script>
var tb=document.createElement("input");
with(tb)
{
type="text";
value="请输入性别";
maxLength="5";
}
document.body.appendChild(tb);
</script>
--------------------------------------------------------------------
--------------------------------------------------------------------
checkbox
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function chkall_onclick(mychecked)
{
var chks=document.frm.elements["chkmusic"];
for(var i=0;i<chks.length;i++)
{
chks[i].checked=mychecked;
}
}
</script>
</HEAD>
<BODY>
<form name="frm">
<table border="1">
<tr>
<td><input type="checkbox" name="chkall" οnclick="chkall_onclick(this.checked);">全选</input>
</td>
<td>歌手名
</td>
<td>歌曲名
</td>
</tr>
<tr>
<td><input type="checkbox" name="chkmusic"></input>
</td>
<td>张学友
</td>
<td>一路有你
</td>
</tr>
<tr>
<td><input type="checkbox" name="chkmusic"></input>
</td>
<td>刘德华
</td>
<td>给你一杯忘情水
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
--------------------------------------------------------------------
--------------------------------------------------------------------
radio
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function btnEnter_onclick()
{
var selectvalue;
var ary=document.frm.star;
for(var i=0;i<ary.length;i++)
{
if(ary[i].checked)
{
selectvalue=ary[i].value;
break;
}
}
alert(selectvalue);
}
</script>
</HEAD>
<BODY>
<form name="frm">
<input type="radio" value="1" name="star">水瓶座</input>
<input type="radio" value="2" name="star">白羊座</input>
<input type="radio" value="3" name="star">天蝎座</input>
<input type="radio" value="4" name="star">狮子座</input>
<input type="button" id="btnEnter" value="确定" onClick="btnEnter_onclick();"/>
</form>
</BODY>
</HTML>
--------------------------------------------------------------------
--------------------------------------------------------------------
select
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function btnadd_onclick()
{
var addvalue=document.frm.txtName.value;
var myselect=document.frm.myselect;
var op=new Option();
op.text=addvalue;
op.value=addvalue;
myselect.options.add(op);
}
function btndel_onclick()
{
var myselect=document.frm.myselect;
op=myselect.options[myselect.selectedIndex];
alert(op.text);
myselect.remove(myselect.selectedIndex);
//myselect.options.length=0;
//myselect.innerHTML="";
//myselect.remove();
}
</script>
</HEAD>
<BODY>
<form name="frm">
<select name="myselect">
<option >请选择</option>
<option>C#</option>
<option>JAVA</option>
<option>C++</option>
<option>C</option>
<option>pascal</option>
<option>javasrcipt</option>
</select>
<input type="text" name="txtName"/>
<input type="button" id="btnadd" onClick="btnadd_onclick();" value="添加"/>
<input type="button" id="btndel" onClick="btndel_onclick();" value="删除"/>
</form>
</BODY>
</HTML>
--------------------------------------------------------------------
--------------------------------------------------------------------
style
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
window.οnscrοll=myscrool;
function myscrool()
{
var mydiv=document.getElementById("div1");
mydiv.style.top=document.body.scrollTop+100+"px";
}
function myclick()
{
var mydiv=document.getElementById("div1");
mydiv.style.display="none";
}
</script>
</HEAD>
<BODY>
<div id="div1" style="position:absolute;left=50px;top=100px;">
<img src="image/183823_140280.gif"/>
<span style="cursor:hand;" onClick="myclick();">关闭</span>
</div>
<p>段落</p>
<p>段落</p> </BODY>
</HTML>
--------------------------------------------------------------------
--------------------------------------------------------------------
var ary=new Array();
ary[0]="yes";
ary[1]="no";
//document.write(ary.toString());
var ary=["red","yellow","blue"];
document.write(ary+"<br/>");
document.write(ary.length);
//用for--in --迭代
for(var index in ary){
document.write(" "+ary[index]+" ");
}
//拼接
document.write(ary.join("-")+"<br/>");
//反转,对其本身作改变
document.write(ary.reverse()+"<br/>");
//排序,按ASII码
ary.sort();
document.write(ary);
--------------------------------------------------------------------
<script>
function mycompare(x,y)
{
var result=0;
var a=parseInt(x);
var b=parseInt(y);
if(a>b)
{
result=1;
}
else if(a<b)
{
result=-1;
}
return result;
}
var ary=new Array();
var ary=["ww","yy","aaa"];
ary[0]="zs";
ary[1]="ls";
document.write(ary+"<br/>");
ary[2]="bbb";
document.write(ary.length);
for(var index in ary)
{
document.write(ary[index]+"<br/>")
}
//数组元素拼接
document.write(ary.join()+"<br/>");
//数组元素转置
ary.reverse();
document.write(ary+"<br/>");
var ary1=[2,20,4,5,12];
document.write(ary1+"<br/>");
//排序
ary1.sort(mycompare);
document.write(ary1+"<br/>");
//数组拼接
var ary2=["a","b","c"];
var ary3=["e","f"];
var ary4=ary2.concat(ary3,ary3);
var ary5=ary4.concat("g","h",ary3);
document.write(ary5+"<br/>")
//返回选定的元素
document.write( ary5.slice(2,80)+"<br/>");
//替换元素
var ary6=["zs","ls","ww"];
document.write(ary6+"<br/>")
ary6.splice(1,1,"adsf","adsf");
document.write(ary6+"<br/>")
document.write(ary6.pop()+"<br/>");
document.write(ary6);
</script>
--------------------------------------------------------------------
锯齿数组
var arys=[["SQL SERVER","C# OOP"],["WEB FORM","HTML/CSS/JAVASCRIPT","ORACLE","ADO.NET"],["ASP.NET","LINQ"]];
document.write(11+"----------------------------<br/>");
for(var index in arys){
document.write(arys[index]+"<br/>");
}
document.write("<hr/>");
for(var index in arys){
for(var i in arys[index]){
document.write("第"+(parseInt(index)+1)+"个子数组里面的元素为:"+arys[index][i]+"<br/>");
}
document.write("<hr/>");
}
--------------------------------------------------------------------
--------------------------------------------------------------------
时间
var now=new Date();
document.write(now.toTimeString()+"<br/>");
document.write(now.toLocaleString()+"<br/>");
document.write(now.toDateString()+"<br/>");
var now = new Date();
var year = now.getYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var day = now.getDay();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
var dayStr = "日一二三四五六";
var strDateTime = "今天日期是:" +year + "年" + month + "月" + date + "日 星期" + dayStr.charAt(day) + " 现在时间是:" + hour + "时" + minute + "分" + second + "秒";
document.write(strDateTime+"<br/>");
--------------------------------------------------------------------
<html>
<head>
<title>网站地址管理</title>
<script type="text/javascript">
var stopid;
function timeGo(){
var time=new Date();
document.getElementById("heretime").innerText=time.toLocaleString();
}
function timeStart(){
stopid=window.setInterval("timeGo()",1000);
}
function timeStop(){
window.clearInterval(stopid);
}
</script>
</head>
<body>
<input type="button" value="开始" onClick="timeStart();"/>
<input type="button" value="停止" onClick="timeStop();"/><br/><br/>
<span id="heretime"></span>
</body>
</html>
--------------------------------------------------------------------
<html>
<head>
<title>网站地址管理</title>
<script type="text/javascript">
var stopid;
function timeStart(){
var time=new Date();
document.getElementById("heretime").innerText=time.toLocaleString();
stopid=window.setTimeout("timeStart();",1000);
}
function timeStop(){
window.clearTimeout(stopid);
}
</script>
</head>
<body>
<input type="button" value="开始" οnclick="timeStart();"/>
<input type="button" value="停止" οnclick="timeStop();"/><br/><br/>
<span id="heretime"></span>
</body>
</html>
--------------------------------------------------------------------
函数判断质数
function ck(no){
var flag=true;
for(var i=2;i<no/2;i++){
if(no%i==0){
flag=false;
}
}
return flag;
}
var num=33565;
document.write(ck(num)?"这是一个质数":"这不是质数");
--------------------------------------------------------------------
--------------------------------------------------------------------
创建元素
<script>
var tb=document.createElement("input");
with(tb)
{
type="text";
value="请输入性别";
maxLength="5";
}
document.body.appendChild(tb);
</script>
--------------------------------------------------------------------
--------------------------------------------------------------------
checkbox
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function chkall_onclick(mychecked)
{
var chks=document.frm.elements["chkmusic"];
for(var i=0;i<chks.length;i++)
{
chks[i].checked=mychecked;
}
}
</script>
</HEAD>
<BODY>
<form name="frm">
<table border="1">
<tr>
<td><input type="checkbox" name="chkall" οnclick="chkall_onclick(this.checked);">全选</input>
</td>
<td>歌手名
</td>
<td>歌曲名
</td>
</tr>
<tr>
<td><input type="checkbox" name="chkmusic"></input>
</td>
<td>张学友
</td>
<td>一路有你
</td>
</tr>
<tr>
<td><input type="checkbox" name="chkmusic"></input>
</td>
<td>刘德华
</td>
<td>给你一杯忘情水
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
--------------------------------------------------------------------
--------------------------------------------------------------------
radio
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function btnEnter_onclick()
{
var selectvalue;
var ary=document.frm.star;
for(var i=0;i<ary.length;i++)
{
if(ary[i].checked)
{
selectvalue=ary[i].value;
break;
}
}
alert(selectvalue);
}
</script>
</HEAD>
<BODY>
<form name="frm">
<input type="radio" value="1" name="star">水瓶座</input>
<input type="radio" value="2" name="star">白羊座</input>
<input type="radio" value="3" name="star">天蝎座</input>
<input type="radio" value="4" name="star">狮子座</input>
<input type="button" id="btnEnter" value="确定" onClick="btnEnter_onclick();"/>
</form>
</BODY>
</HTML>
--------------------------------------------------------------------
--------------------------------------------------------------------
select
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function btnadd_onclick()
{
var addvalue=document.frm.txtName.value;
var myselect=document.frm.myselect;
var op=new Option();
op.text=addvalue;
op.value=addvalue;
myselect.options.add(op);
}
function btndel_onclick()
{
var myselect=document.frm.myselect;
op=myselect.options[myselect.selectedIndex];
alert(op.text);
myselect.remove(myselect.selectedIndex);
//myselect.options.length=0;
//myselect.innerHTML="";
//myselect.remove();
}
</script>
</HEAD>
<BODY>
<form name="frm">
<select name="myselect">
<option >请选择</option>
<option>C#</option>
<option>JAVA</option>
<option>C++</option>
<option>C</option>
<option>pascal</option>
<option>javasrcipt</option>
</select>
<input type="text" name="txtName"/>
<input type="button" id="btnadd" onClick="btnadd_onclick();" value="添加"/>
<input type="button" id="btndel" onClick="btndel_onclick();" value="删除"/>
</form>
</BODY>
</HTML>
--------------------------------------------------------------------
--------------------------------------------------------------------
style
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
window.οnscrοll=myscrool;
function myscrool()
{
var mydiv=document.getElementById("div1");
mydiv.style.top=document.body.scrollTop+100+"px";
}
function myclick()
{
var mydiv=document.getElementById("div1");
mydiv.style.display="none";
}
</script>
</HEAD>
<BODY>
<div id="div1" style="position:absolute;left=50px;top=100px;">
<img src="image/183823_140280.gif"/>
<span style="cursor:hand;" onClick="myclick();">关闭</span>
</div>
<p>段落</p>
<p>段落</p> </BODY>
</HTML>
--------------------------------------------------------------------
--------------------------------------------------------------------