window.open(url, name, features)
三個參數分別是:載入新視窗的頁面 URL、新視窗的名稱,以及特性字串(並可指定是否用新載入的頁面取代目前頁面)。關閉視窗則用:
window.close()
alert("hello world!"); // 只有一個按鈕的提示框
confirm("Are you sure?"); // 確認/取消,回傳布林值
prompt("你的名字是什麼?", ""); // 帶輸入框的提示,回傳輸入內容
setTimeout("alert('hello world!')", 3000); // 3 秒後執行一次
clearTimeout(id); // 取消計時器
setInterval("alert('hello world')", 3000); // 每 3 秒執行一次
clearInterval(id); // 取消週期執行
window.history.go(-1); // 回到上一頁
window.history.back(); // 回到上一頁
window.history.go(1); // 前進一頁
window.history.forward(); // 前進一頁
window.history.length; // 查詢歷史中的頁面數
document.links[0]; // 存取連結
document.images[0]; // 存取圖像
document.images["imgHome"];
document.forms[0]; // 存取表單
document.forms["frmSubscribe"];
href 屬性代表目前載入頁面的完整 URL,可讀也可寫;賦值後瀏覽器會跳轉並載入新文件。
userData.nodeName // 節點名稱
nodeValue // 節點的值,主要用於文本節點;元素節點回傳 null
nodeType // 節點類型
firstChild // 第一個子節點
lastChild // 最後一個子節點
childNodes // 所有子節點的集合
previousSibling // 前一個兄弟節點(同層)
nextSibling // 後一個兄弟節點(同層)
attributes // 包含代表元素各項特性的 Attr 物件,僅用於 Element 節點
appendChild // 在最後新增一個節點
removeChild // 刪除一個節點
replaceChild // 替換節點
insertBefore // 在指定節點之前插入
createElement // 建立元素節點
createTextNode // 建立文本節點
cloneNode(true); // 深度複製,連子節點一起複製
cloneNode(false); // 淺度複製,只複製自身
getElementById // 依指定的 id 查找
getElementsByTagName // 依標籤名查找,回傳陣列形式
getElementsByName // 依 name 屬性查找
getAttribute() // 查找屬性
setAttribute() // 修改或設定屬性,例如 setAttribute("class", "red")
removeAttribute() // 刪除屬性
使用 innerHTML 可以直接覆寫或新增元素內部的 HTML 內容,是最簡便的做法。