48 JS

1•历史对象: 用以存储客户端最近访问的网址清单。

格式:

•history.属性 history.方法(参数)

<a href="js9.jsp">单击</a>

<a href="#" onclick="history.back();return false;">返回</a>

注:一定要有return false

2位置对象: 用来代表特定窗口的URL信息。

格式:
•location.属性 location.方法(参数)

示例 倒计时进入新的网页

var second = 5;
    function countDown()
    {
        if (second > 0)
        {
            document.getElementById("second").innerHTML = second--;

        } else

        {
            location.href = "http://www.baidu.com";
            clearInterval(timer);
        }

    }

    function pageload()
    {
        var timer = setInterval("countDown();", 1000);

    }



<body onload="pageload();">
    <font color="red" id="second">5</font>秒后进入新的页面

</body>

3 focus移动焦点

function movenext(object,index)
    {
        if (object.value.length==3)
        {
            document.forms[0].elements[index+1].focus();
        }
    }
    
    function show()
    {
            var result="";
        for(var i=0;i<4;i++)
        {
            result+=    document.forms[0].elements[i].value+".";
        }
    
            alert(result);
        
    }



<body onload="document.forms[0].elements[0].focus();">
  <form >
  <input maxlength="3" size="3" onkeyup="movenext(this,0);">-
   <input maxlength="3" size="3" onkeyup="movenext(this,1);">-
   <input maxlength="3" size="3" onkeyup="movenext(this,2);">-
   <input maxlength="3" size="3" onkeyup="movenext(this,3);">
   <input type="button" value="show" onclick="show();">
  </form>

4 Cookie对象

是一种以文件(Cookie文件)的形式保存在客户端硬盘的Cookies文件夹中的用户数据信息(Cookie数据)。Cookie文件由所访问的Web站点建立,以长久的保存客户端与Web站点间的会话数据,并且该Cookie数据只允许被所访问的Web站点进行读取。

有两种类型的cookie
1) 持久性cookie,会被存储到客户端的硬盘上。
2) 会话(session)Cookie:不会存储到客户端的硬盘上,而是放在浏览器进程所处的内存当中,当浏览器关闭则该会话cookie就销毁了。

Cookie文件的格式:
•NS:Cookie.txt IE:用户名@域名.txt

var today = new Date();
    
    var expireDay = new Date();
    
    var msPerMonth = 24 * 60 * 60 * 1000 * 31;
    
    expireDay.setTime(today.getTime() + msPerMonth);
    
    document.cookie = "name=zhang;expires=" + expireDay.toGMTString();
    
    document.writeln("cookie已经写到硬盘上了");
    
    document.writeln("内容是:" + document.cookie);
    
    document.writeln("有效日期是:");
    
    document.writeln(expireDay.toGMTString());

评论

暂无评论