Javascript s04

 

a. alert(new Date(1992,2,30,15,44,9));

         月份要加一

        

b.在新浪里如何1个中文占一个与英文2个占一个 

         1.取出用户输入的内容

         var str=document.getElementById("msg").value;

         var regexp=/^[\x00-\xff]$/;

         for(var i=0;i<str.length;i++){

                   if(regexp.test(str[i])){

                            length+=1;

                   }else{

                            length+=2;

                   }

         }

         alert(Math.ceil(length/2));

        

一.BOM   浏览器对象(在全局对象Window里面)

         1.时钟=setTimeout();(是Window的方法)

         延时调用(执行);只调用一次

         a.setTimeout(function,n000);

           不加括号,是延时调用函数

        

         b.setTimeout(function(),n000);

         加括号的时候是立刻调用,要有return,否则是undefined;

        

         c.非要用要加上引号,变成字符串

           setTimeout("function()",n000);

           eval调用

        

         d.如果函数里面加参数

                   setTimeout("function("+'str'+")",n000);

                   "function("      'str'     ")"

        

         e.setTimeout("function('str')",1000);    

                   e和d是一样的效果.e是字符串连接

        

        

         2.clearTimeout(时钟)     

        

         3.setInterval(函数,时间)

         会反复执行,不需要在函数中重复调用了

 

二.window 对象的重要属性

                   a.status  很少用,状态栏内容 IE

                   b.self        当前窗口

                   c.parent   父窗体;防止别人把我的网页放在iframe中

                   if(parent!=self){

                            alert("不要盗用我的内容");

                   }

                  

                   其他重要方法

                   d.alert

                   e.confirm()

                  

                   //了解即可

                   window.open(URL,name,features,replace);

                  

                   f.location对象

                  

                            主要 用于浏览器定位和导航

                            三种方法,让a标签不跳转,取消超链接,跳转页面

                            location.href    当前浏览器地址栏的url

                            1.<a href="javascript:;" onclick="test()">;

                            2.<a href="" onclick="return false">;

                            3.<a 不写href>没有下划线

                            跳转页面,刷新页面

                           

                            用js跳转页面的几种方式

                            replace 用新的文档替换当前文档

                            location="http://www.baidu.com";

                            location.replace('http://www.location.com')

                            location.href:返回是当前的UR

                            <a href="javascript:;" onclick="location.href="www.baidu.com">

                  

                            用js刷新页面

                            location.reload(true)        强制刷新

                            location=location;

                  

                   g.history对象

                  

                            history.go(-1) 后退

                            history.back()    前一个URL里

                            history.foward()

                           

                   h.Navigator      对象包含有关浏览器的信息。

 

                            只读属性

                            document.all  IE有这个属性,别的浏览器没有

                           

                            Navigator.userAgent

                           

                   i.screen屏幕对象

                            screen.width

                            screen.height

 

三.具有ID属性的对象,会自动注册成window的属性,不推荐是用.                 

 

四.css属性变换成js属性    margin-left   则改为 mrginLeft       

        

        

        

        

        

posted @ 2013-06-03 20:07  午时的海  阅读(171)  评论(0编辑  收藏  举报