Javascript大纲

Posted on 2012-03-19 16:23  binbin8890  阅读(216)  评论(0)    收藏  举报

常用语法 脚本语言 基于对象

  数据类型 数字/字符串/布尔/对象 undefined/null   

对象类型包含:function

引深匿名函数  

数据类型判断 typeof  

函数 arguments

关键字 动态参数  NaN  转换布尔 false :null undefined 0 NaN ''  for( in )

 常用方法与对象  String 对象 Math对象 日期 正则, toFixed parseInt parseFloat

数组访问  push() pop() shift() unshift()  length

对象字面量  延伸:eval() 与 JSON

浏览器对象模型(BOM)

  window:代表浏览器窗口

代表全局  window.open   

主窗体: opener   

子窗体: var newWindow = window.open(.....  window.showModalDialog(....   向弹出窗体传值:第二个参数/ 在弹出窗体接受参数:dialogArguments   在弹出窗体 window.returnValue = .... /

在主窗体 var rtValue = window.ShowModalDialog(....  window.close()  window.location (.href .protocol .host .hostname .port .pathname .search .hash)   例:http://www.test.com:8080/index.aspx?ID=1#2   .reload() .replace()  window.history (.go() .back() froward())  alert() confirm() prompt()  var myTO = settimeout('testFun();',1000);clearTimeout(myTO);  setInterval() clearInterval  ------------  window.document  document.open() document.write() document.close()  ------------  document.cookie   cookie原理 与读写 事件  兼容性问题 W3C与微软  事件分组:鼠标(click/dbclick/mousemove/mousedown/mouseup/mouseover/mouseout)

  键盘(keydown/keypress)

  接口(blur/focus/change/load/unload/reset/submit/resize/scroll)

 事件取消 return false/ie:event.returnValue = false/W3C:

事件.preventDefault()

 事件模拟

 注册事件处理 html行内/事件名=/ie:元素.attachEvent('onclick',TestFun)/w3c:addEventListener('click',TestFun,false) 及移除  事件冒泡事件捕获 w3c捕获与冒泡 ie冒泡  取消冒泡 w3c:stopPropagation() ie:cancelBubble = true  事件对象 ie:event w3c:(e) 解决方案 var evt = e || window.event   属性type /srcElement与target

  文档对象模型Dom

 文档结构window->document-><html>-><head>与<body>  寻找元素getElementByID() getElementsByName() getElementsByTagName() 返回元素或元素列表 注意列表不是Array  访问周边元素 parentNode firstChild lastChild previousSibling nextSibling  子节点 childNodes[] children[] (不包含文本节点)  表格 rows集合 tr的cells集合 rowIndex td的cellIndex  节点信息 nodeName与nodeType nodeValue nodeType  元素内容 innerHTML outerHTML innerText outerText  获得与设置属性值 getAttribut() setAttribut()     修改文档树 appendChild() insertBefore() removeChild() replaceChild()  创建克隆元素 createElement()与createTextNode()  元素.coloneNode()  自定义属性  节点列表 相当于只读数组

操作CSS

 element.style.  破折号改驼峰表示法 font-size element.style.fontSize  element.className

面向对象的javascript 

 类与继承

 prototype call apply

this关键字  

1. (A)作为普通函数直接调用时,this指向window对象.  2. (B)作为控件事件触发时  1) inline event registration 内联事件注册 .将事件直接写在HTML代码中(<element  onclick=”doSomething()”>), 此时this指向 window对象 。  2) Traditional event registration 传统事件注册 (DHTML方式).  形如 element.onclick = doSomething; 此时this指向 element对象  3) <element onclick=”doSomething(this)”>作为参数传递可以指向element  3. (C)作为对象使用时this指向当前对象。形如:new doSomething();  4. (D)使用apply 或者call方法时,this指向所传递的对象。  形如:var obj={}; doSomething.apply(obj,new Array(”nothing”);

 

 

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3