JavaScript基礎學習--零碎

來源:互聯網
上載者:User

標籤:add   src   []   png   jquery   事件   mod   pre   self   

1、如果WINDOW對象是常規HTML頁面, TOP就是SELF      var top = document.getElementById(‘top‘);     top.innerHTML     //undefined 2、 ev.stopPropagation(); // 阻止事件冒泡
li.onmouseout = function(ev) {    ev.stopPropagation(); //組織事件冒泡};oStar.onmouseout = function() {    for (var i = 0; i < aLi.length; i++) {        var img = aLi[i].getElementsByTagName(‘img‘)[0];        img.src = ‘images/darkstar.png‘;    }};
 3、var aLi_right = aUl[1].getElementsByTagName(‘li‘);     // aLi_right instanceof Array  //false     --它是object,但是不是數組,所以不能用數組拼接方法concat     -- 對象轉化並拼接成數組的方式:for迴圈
var aUl = document.getElementsByTagName(‘ul‘);var aLi_left = aUl[0].getElementsByTagName(‘li‘);var aLi_right = aUl[1].getElementsByTagName(‘li‘);var toConcatArray = function(left, right) {    var arrLi = [];    for (var i = 0; i < left.length; i++) {        arrLi.push(left[i]);    }    for (var j = 0; j < right.length; j++) {        arrLi.push(right[j]);    }    return arrLi;};var aLi = toConcatArray(aLi_left, aLi_right);//但是,如果某塊中不需要排除其他li,只有目標li,可以直接://var aLi = document.getElementsByTagName(‘li‘);
 4、 擷取視口大小和文檔大小
/*視口的大小,部分行動裝置瀏覽器對innerWidth的相容性不好,需要 *document.documentElement.clientWidth或者document.body.clientWidth *來相容(混雜模式下對document.documentElement.clientWidth不支援)。 *使用方法 : getViewPort().width; */function getViewPort() {    if (document.compatMode == "BackCompat") { //瀏覽器嗅探,混雜模式        return {            width: document.body.clientWidth,            height: document.body.clientHeight        };    } else {        return {            width: document.documentElement.clientWidth,            height: document.documentElement.clientHeight        };    }}//獲得文檔的大小(區別與視口),與上面擷取視口大小的方法如出一轍function getDocumentPort() {    if (document.compatMode == "BackCompat") {        return {            width: document.body.scrollWidth,            height: document.body.scrollHeight        };    } else {        return {            width: Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth),            height: Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight)        }    }}
clientHeight:內容高度+padding高度  ,jQuery中的innerHeight()方法返回的就是這個高度。   offsetHeight:內容高度+padding高度+邊框寬度  ,jQuery中的outerHeight()方法返回的就是這個高度   注意:用document.getElementById(‘bottom‘).style.[ height | width ]   dom.style.width這種方式 只能取到行內屬性, 而不是css屬性        

JavaScript基礎學習--零碎

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.