js 小结

来源:互联网 发布:手机淘宝设置发货地址 编辑:程序博客网 时间:2024/06/05 04:32
Js    小节1. document.getElementById() 得到一个对象2. isNaN( x ) 判断是否是数字3. 那些老旧的实例可能会在 <script> 标签中使用 type="text/javascript"。现在已经不必这样做了。JavaScript 是所有现代浏览器以及 HTML5 中的默认脚本语言4. document.getElementById.innerHTML = "";5.请使用 document.write() 仅仅向文档输出写内容。如果在文档已完成加载后执行 document.write,整个 HTML 页面将被覆盖6.您可以在文本字符串中使用反斜杠对代码行进行换行。下面的例子会正确地显示:document.write("Hello \World!");7.在计算机程序中,经常会声明无值的变量。未使用值来声明的变量,其值实际上是 undefined。

在执行过以下语句后,变量 carname 的值将是 undefined:

8.java 对象的问题     对象由花括号分隔。在括号内部,对象的属性以名称和值对的形式 (name : value) 来定义。属性            由逗号分隔:var person={firstname:"Bill", lastname:"Gates", id:5566};上面例子中的对象 (person) 有三个属性:firstname、lastname 以及 id。空格和折行无关紧要。声明可横跨多行:var person={firstname : "Bill",lastname  : "Gates",id        :  5566};对象属性有两种寻址方式:实例name=person.lastname;name=person["lastname"];9.Undefined 和 Null    Undefined 这个值表示变量不含有值。    可以通过将变量的值设置为 null 来清空变量    10.JavaScript 变量的生存期    JavaScript 变量的生命期从它们被声明的时间开始。    局部变量会在函数运行以后被删除。    全局变量会在页面关闭后被删除。    向未声明的 JavaScript 变量来分配值    如果您把值赋给尚未声明的变量,该变量将被自动作为全局变量声明。    这条语句:    carname="Volvo";    将声明一个全局变量 carname,即使它在函数内执行。  11. for in这个有东西  12. break; continue;  还有就是labelname;  13. js  报错的话             try{        }catch(err){        }             抛出异常是throw 14        JavaScript 能够改变页面中的所有 HTML 元素        JavaScript 能够改变页面中的所有 HTML 属性        JavaScript 能够改变页面中的所有 CSS 样式        JavaScript 能够对页面中的所有事件做出反应 15  更改内容  innerHTML       改变HTML 属性: document.getElementById('id').attribute =       改变HTML 样式:document.getElementById().style.property =       例子: document.getElementById().style.visibility ='hidden'  or 'visible' 16  常用的事件  onclick   点击事件               onload   加载事件            onchange 内容发生改变的时候               onmouseover  鼠标放在上面的时候            onmouseout   鼠标离开的时间            onmousedown 鼠标按下来的时候            onmouseup      鼠标松开的时候 17  document.createElement(‘’) 创建一个节点       document.getElementById().appendChild(); 添加元素       document.getElementById().removeChild(); 删除子孩子 18  字符串的方法   indexOf()   match()   replace() 19 获得长宽高        var w=window.innerWidth        || document.documentElement.clientWidth        || document.body.clientWidth;        var h=window.innerHeight        || document.documentElement.clientHeight        || document.body.clientHeight;        x=document.getElementById("demo");        x.innerHTML="浏览器的内部窗口宽度:" + w + ",高度:" + h + "。"   20 window.screen 对象包含有关用户屏幕的信息。        screen.availWidth 属性返回访问者屏幕的宽度,以像素计,减去界面特性        screen.availHeight 属性返回访问者屏幕的高度,以像素计,减去界面特性,比如窗口栏。   21 window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面。        location.hostname 返回 web 主机的域名        location.pathname 返回当前页面的路径和文件名        location.port 返回 web 主机的端口 (80 或 443)        location.protocol 返回所使用的 web 协议(http:// 或 https://)        location.href  返回当前页面        location.pathname 属性返回 URL 的路径名        location.assign() 方法加载新的文档    22  window.history 对象包含浏览器的历史。        history.back() 后退        history.forward() 前进    23 window.navigator 对象包含有关访问者浏览器的信息。        txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";        txt+= "<p>Browser Name: " + navigator.appName + "</p>";        txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";        txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";        txt+= "<p>Platform: " + navigator.platform + "</p>";        txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";        txt+= "<p>User-agent language: " + navigator.systemLanguage + "</p>"    24  javascript  三种消息框       禁告: alert()       确认框  var  tj = confirm()       提示框   prompt('文本',默认值)    25  setTimeout() 未来的某时执行代码          clearTimeout 取消执行的代码   26 cookie 的存储    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)            }          }    }
0 0
原创粉丝点击