javascript学习资源

javascript+jscript+html:http://pan.baidu.com/share/link?shareid=163521&uk=1678594189

jsp+ajax:http://pan.baidu.com/share/link?shareid=163530&uk=1678594189

(Asynchronous JavaScript and XML 异步JavaScript和XML)

jquery:http://www.cnblogs.com/zhangziqiu/tag/jQuery/

javascritp:http://www.w3school.com.cn/js/

ajax:http://www.w3school.com.cn/ajax/

html:http://www.w3school.com.cn/html/

猜数游戏:

View Code
<html>
<body>
<script type="text/javascript">
randNum=Math.floor(Math.random()*100)+1;
big=100;
small=1;
time=0;
document.write(randNum+"<br>");
x=prompt("enter a number between  "+small+" and "+big+" :","")
//document.write(x+"<br>");
while(x!=null)
{
time=time+1;
if(x==randNum) 
{
document.write("Great it is:"+randNum+"用了"+time+"次"+"<br>");break;}
else if(x<small){alert("Error! the value is too low"+"<br>")}
else if(x>big) {alert("Error! the value is too hight"+"<br>")}
else if(x>randNum) big=x;
else if(x<randNum) small=x;
x=prompt("enter a number between"+small+"and"+big+":","")
}
</script>
</body>
</html>

 

View Code
<script type="text/javascript">// <![CDATA[
var array0=new Array();
i=0;
randNum=Math.floor(Math.random()*100)+1;
big=100;
small=1;
time=0;
//document.write(randNum+"<br>");
x=prompt("enter a number between  "+small+" and "+big+" :","")
array0[i++]=x;
//document.write(x+"<br>");
while(x!=null)
{
time=time+1;
if(x==randNum) 
{document.write("Great 答案是:"+randNum+"你用了"+time+"次"+"<br>");break;}
else if(x<small){alert("Error! the value is too low"+"<br>")}
else if(x>big) {alert("Error! the value is too hight"+"<br>")}
else if(x>randNum) big=x;
else if(x<randNum) small=x;
x=prompt("enter a number between"+small+"and"+big+":","");
array0[i++]=x;
}
document.write("你输入的值分别是:"+"<br>");
for(j=0;j<i;j++)
{
document.write(array0[j]+" ");
}
// ]]></script>

 cookie例子( 在javascript标签中添加checkCookie();的调用。注:定义函数的代码不会自动运行。)

View Code
<script type="text/javascript">
function getCookie(c_name)
{
if (document.cookie.length>0)
{ 
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{ 
c_start=c_start + c_name.length+1 
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
} 
}
return ""
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : "; expires="+exdate.toGMTString())
}

function checkCookie()
{
username=getCookie('username')
if (username!=null && username!="")
  {alert('Welcome again '+username+'!')}
else 
  {
  username=prompt('Please enter your name:',"")
  if (username!=null && username!="")
    {
    setCookie('username',username,365)
    }
  }
}
</script>

 按钮:

<input type="button" value="View message" onclick="message()" />

文本框

<input type="text" name="lastname">

提交按钮

<input type="submit" value="Submit" />

选择框(当选中其它的值时会产生onchange时间进而调用CreateInput()函数)

<select name="select" id="select" onchange="CreateInput()" > 
<option value="1">1</option>
<option value="2">2</option>  
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>  

时钟(弹出一次):

function timedMsg()
{
var t=setTimeout("alert('5 秒!')",5000)
}

时钟:

(运行n次 其中setTimeout第第一个参数为时间到时运行的代码,不是现实的字符串 clearTimeout(t) 为清除时钟T为setTimeout的返回值)

function timedCount()
{
document.getElementById('txt').value=c
c=c+1
t=setTimeout("timedCount()",1000)
}

时钟:

<html>
<head>
<script type="text/javascript">
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
// add a zero in front of numbers<10
m=checkTime(m)
s=checkTime(s)
document.getElementById('txt').innerHTML=h+":"+m+":"+s
t=setTimeout('startTime()',500)
}

function checkTime(i)
{
if (i<10) 
  {i="0" + i}
  return i
}
</script>
</head>

<body οnlοad="startTime()">
<div id="txt"></div>
</body>
</html>

 

 

<script type="text/javascript">// 0) { c_start=document.cookie.indexOf(c_name + "=") if (c_start!=-1) { c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) } } return "" } function setCookie(c_name,value,expiredays) { var exdate=new Date() exdate.setDate(exdate.getDate()+expiredays) document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) } function checkCookie() { username=getCookie('username') if (username!=null && username!="") {alert('Welcome again '+username+'!')} else { username=prompt('Please enter your name:',"") if (username!=null && username!="") { setCookie('username',username,365) } } } checkCookie(); // ]]></script> <script type="text/javascript">// "); x=prompt("enter a number between "+small+" and "+big+" :","") //document.write(x+"
"); while(x!=null) { time=time+1; if(x==randNum) { document.write("Great it is:"+randNum+"用了"+time+"次"+"
");break;} else if(x")} else if(x>big) {alert("Error! the value is too hight"+"
")} else if(x>randNum) big=x; else if(x</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值