基礎(chǔ)篇————————————————————————————————————————————————— history:用來控制網(wǎng)頁前進(jìn)和后退,根據(jù)的是網(wǎng)頁歷史紀(jì)錄 history.back(); //后退 無刷新更改URL:history.pushState(data:json,title:string,url:string);// 會存儲在url歷史中 location:用來控制頁面跳轉(zhuǎn) 定時器:
事件綁定的方法:直接使用元素的onclick屬性: <button onclick="btnhandler(this)"> click me </button> 綁定一個事件:
getElementById("xx").onclick = function(e){ xxxxxxxx; }
事件監(jiān)聽: document.getElementById("xxx").addEventListener('click',function(e){ xxxxxx; }) 注意:事件名稱前不加on 區(qū)別: 注意: $('.btn').click(function (e){ ...... }); $('body’).append('<button class="btn">...</button>'); // 單擊事件不能綁定到新的元素上面
手動調(diào)用事件:element.onclick() || element.onclick.call() ; onchange當(dāng)表單的值改變時觸發(fā)(需鼠標(biāo)抬起,不是即時的)
事件對象:事件對象自動傳遞給回調(diào)函數(shù) element.onclick = function(e){};// e就是事件對象 ----如果事件處理函數(shù)的綁定在元素生成之前,則此元素不能綁定事件處理函數(shù),需重新設(shè)置
|
|