Try   HackMD

JS Window & document Event

基礎語法

// 綁定事件
let my_el = document.getElementById("abc");
my_el.addEventListener("click", function(e){
    // code
});

// 解除綁定事件
my_el.addEventListener("click", function(e){
    // code
});

// 停止預設行為
e.preventDefault()

// 停止事件冒泡
e.stopPropagation()

DOMContentLoaded & load事件

// DOMContentLoaded事件
document.addEventListener("DOMContentLoaded", function(){
    // DOM 載入完成之後
});

// load事件
window.addEventListener("load", function(){
    // 圖片等資源載入完成之後
});

resize事件

window.addEventListener("resize", function(){
    // 使用者若有改變視窗大小,就執行這裡的程式
});

tags: frontend jsnote Back to Front End Homepage
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →