初试ajax基础

这是我javascript第一课,javascript如何获取html页中控件,并设置或获取控件的值,以下是页面的源代码
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312"   />
< title > 无标题文档 </ title >

</ head >

< body >
< script  language ="javascript" >
    
function SetValue()
    
{
        
var myDom= document.getElementById("textbox1")
//        var myDom=document.all.textbox1;
//
        var myDom=document.all.form1.textbox1;
        myDom.value="123";
    }

</ script >
< form  id ="form1" >
< input  id ="textbox1"  name ="textbox"  type ="text"  maxlength ="50"  onmousedown ="SetValue()"    />
</ form >
</ body >
</ html >
代码中注释的语句,也同样可以获取到“文本框”

第二课:如何使用setTimeout和setInterval,二者之间有什么区别?
先看setInterval("方法名","时间间隔"),该方法作用是:它从载入后,每隔指定的时间就执行一次表达式.
下面页面中函数的功能就是你将页面打开15秒后自动关闭,并将倒数计时写在页面上
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312"   />
< title > 无标题文档 </ title >

</ head >

< body  >
< script >
    
var i=0;
    
var count=16;
    
function GetDate()
    
{
        i
=i+1;
        
var myDiv = document.all.div1;
        myDiv.innerHTML
= count - i;
        
if((count-i)==0)
        
{
            window.close();
        }

        
    }

</ script >
< div  id ="div1"   ></ div >
</ body >
</ html >


下面来看看setTimeout():在载入后延迟指定时间后,去执行一次表达式,仅执行一次

< script language = " javascript " >
var  i;
i
= 0 ;
function  reloop()
{
i
=i+1;
alert(String(i));
setTimeout(
"reloop()",1000);
}

reloop();

初试javascript,希望能给大家一点小小帮助,同时热切期待高手的指点.....


 

转载于:https://www.cnblogs.com/pkurain/archive/2008/06/09/1216359.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值