《JavaScript高级程序设计》笔记(2)

闭包

function createFunctions(){
     var result = new Array();  
    for (var i=0; i < 10; i++){
         result[i] = function(){
             return i;
         };
     }  
    return result; }
//i均为10
function createFunctions(){
     var result = new Array();  
    for (var i=0; i < 10; i++){
         result[i] = function(num){
             return function(){
                 return num; 
            };
         }(i);
     }  
    return result; }
//i为1,2,3…10

BOM

window对象

在 IE9+、Safari和Firefox 中,outerWidth 和 outerHeight 返回浏览器窗口本身的尺寸(无论是从外层的 window 对象还是从 某个框架访问)。在Opera中,这两个属性的值表示页面视图容器①的大小。而innerWidth 和innerHeight 则表示该容器中页面视图区的大小(减去边框宽度)。在 Chrome 中,outerWidth、outerHeight 与 innerWidth、innerHeight 返回相同的值,即视口(viewport)大小而非浏览器窗口大小。在 IE、Firefox、Safari、Opera 和 Chrome 中,document.documentElement.clientWidth 和 document.documentElement.clientHeight 中保存了页面视口的信息。在 IE6中,这些属性必须在 标准模式下才有效;如果是混杂模式,就必须通过document.body.clientWidth和document.body. clientHeight 取得相同信息。而对于混杂模式下的 Chrome,则无论通过 document.documentElement 还是 document.body 中的 clientWidth 和 clientHeight 属性,都可以取得视口的大小。

window.open()
setTimeout()、clearTimeout()、setInterval()、clearInterval()
alert()、confirm()和 prompt()

location对象

location.href = "";

history对象

history.go()

DOM

  • getAttribute() setAttribute()
  • document.createElement()
  • 父、子节点
  • document.createTextNode()

DOM扩展

HTML5

  • getElementsByClassName()方法
  • classList 属性

<div class="bd user disabled">...</div>
div.classList.remove("user");

  • innerHTML()
  • scrollIntoView()可以在所有 HTML 元素上调用,通过滚动浏览器窗口或某个容器元素,调用 元素就可以出现在视口中。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容